0

I am trying to retrive an OAuth bearer token from Twitter using file_get_contents (can't use cURL as i'm hosting on GAE)

$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);

But no matter what I seem to do I always get a 401. Maybe I can't see the wood for the trees now but I can't see whats wrong here. The parameters I am passing work fine if I use a cURL based approach.

1 Answer 1

0

Pretty sure your headers need to be separated by \n not commas.

e.g.

'header' => 'Header1: foo\nHeader2: bar',

etc

2
  • no that didn't help, but thanks. in other news i read here that it should be 'http' => array( even though this is an ssl connection Feb 6, 2014 at 10:17
  • Actually you need to use \r\n to separate headers, not just \n.
    – Mars
    Apr 22, 2014 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.