简体   繁体   English

Twitter OAuth-适用于cURL,但不适用于PHP流

[英]Twitter OAuth - works with cURL but not PHP stream

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) 我正在尝试使用file_get_contents从Twitter检索OAuth承载令牌(不能使用cURL,因为我在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. 但是,无论我做什么,我总会得到401。也许我现在看不到树木的木头,但是我看不到这里有什么问题。 The parameters I am passing work fine if I use a cURL based approach. 如果使用基于cURL的方法,我传递的参数可以正常工作。

Pretty sure your headers need to be separated by \\n not commas. 可以肯定,您的标头需要用\\ n而不是逗号分隔。

eg 例如

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

etc 等等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM