title: Making PayPal API calls in PHP without cURL
body: <p>I can't use cURL as Google App Engine doesn't support it.</p>
  
  <p>I am trying to get the access token in step 2 of: <a href="https://developer.paypal.com/docs/integration/direct/make-your-first-call" rel="nofollow">https://developer.paypal.com/docs/integration/direct/make-your-first-call</a></p>
  
  <p>I'm not sure how I should be structuring my call. I have this so far:</p>
  
  <pre><code>$data = array(
      'grant_type' =&gt; 'client_credentials',
      'client_id' =&gt; $sandbox_client_id,
      'secret' =&gt; $sandbox_secret
  
  );
  
  
  $data = json_encode($data);
  
  $context = [
    'http' =&gt; [
      'method' =&gt; 'POST',
      'header' =&gt; 'Content-Type: application/x-www-form-urlencoded' . "\r\n" .
          'Accept: application/json' . "\r\n" .
          'Accept-Language: en_US' . "\r\n"
      ,
      'content' =&gt; $data
    ]
  ];
  $context = stream_context_create($context);
  
  $response = file_get_contents('https://api.sandbox.paypal.com/v1/oauth2/token', false, $context);
  
  echo $response;
  </code></pre>
  
  <p>Which returns this:</p>
  
  <pre><code>Warning: file_get_contents(https://api.sandbox.paypal.com/v1/oauth2/token): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in C:\folder\php\paypal\test.php on line 28
  </code></pre>
  
  <p>Any insight is appreciated!</p>