OAuth token without using cURL


#1

I am trying to retrive an OAuth bearer token using file_get_contents (as I can can’t use cURL because i’m hosting in on Google App Engine)

I am modifying my code to use streams rather than cURL. My cURL works fine, the parameters are correct but when i try to use them without cURL but in a stream context I always hit a 401 error. I figured it might be something to do with how i present/format the headers (/r/n on each line?) but after hours of trying i still can’t get anything to work.
Example:

$context = stream_context_create(array(
        'https' => array(
          'method'  => 'POST',
          'header'  => 'Authorization: OAuth oauth_consumer_key="xxxxkfPTi8NrdAlK0xxxxx", oauth_callback="http://dev.mysite.com/auth/oauth/twitter", oauth_version="1.0", oauth_timestamp="1391622508", oauth_nonce="xxxxxaDoawlKjDODdxczL2JIow0AF1JkGa4fxxxx", oauth_signature_method="HMAC-SHA1", oauth_signature="xxxxznCGJWmBheTa/cCSEINxxxxx"',
          'timeout' => 5,
        ),
      ));
$response = file_get_contents('https://api.twitter.com/oauth/request_token', false, $context);</code>

Maybe I can't see the wood for the trees now but I can't see whats wrong here.. Any suggestions much appreciated !

Mark