Twitter API停止工作(未经授权)



我使用自己的代码生成一个oauth请求到twitter API,但它停止工作几天前(我只是刚刚注意到)。我现在已经切换到twitteroauth,但问题仍然完全相同(用一些XXXX替换了部分密钥):

* About to connect() to stream.twitter.com port 443 (#0)
*   Trying 199.16.156.110...
* connected
* Connected to stream.twitter.com (199.16.156.110) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using RC4-SHA
* Server certificate:
*        subject: C=US; ST=California; L=San Francisco; O=Twitter, Inc.; OU=Twitter Security; CN=stream.twitter.com
*        start date: 2013-10-09 00:00:00 GMT
*        expire date: 2016-12-30 23:59:59 GMT
*        subjectAltName: stream.twitter.com matched
*        issuer: C=US; O=VeriSign, Inc.; OU=VeriSign Trust Network; OU=Terms of use at https://www.verisign.com/rpa (c)10; CN=VeriSign Class 3 Secure Server CA - G3
*        SSL certificate verify ok.
> GET /1.1/statuses/sample.json HTTP/1.1
> User-Agent: curl/7.26.0
> Host: stream.twitter.com
> Accept: */*
> Authorization: OAuth oauth_consumer_key="XXXXXT0ayBaTgZ2w", oauth_nonce="XXXXXaa67fb89550XXXXXX", oauth_signature="XXXXXXWq2JQWiykA%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1395304184", oauth_token="461014117-xXXXXXXXXXbgolyzewmAido0104sjmIV053U3e", oauth_version="1.0"
>
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 401 Unauthorized
< WWW-Authenticate: OAuth realm="Firehose"
< Content-Type: text/html
< Cache-Control: must-revalidate,no-cache,no-store
< Transfer-Encoding: chunked
<
<html>n<head>n<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>n<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing '/1.1/statuses/sample.json'. Reason:
<pre>    Unauthorized</pre>
</body>
</html>
* Connection #0 to host stream.twitter.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
在dev.twitter.com上的"Test OAuth"功能给了我一个curl命令,执行的工作,所以我修改了PHP代码以输出这样的命令。然而,这行不通。相同的'unauthorized'错误;

dev.twitter.com给我的Curl命令:

curl --get 'https://stream.twitter.com/1.1/statuses/sample.json' --header 'Authorization: 
OAuth oauth_consumer_key="XXXXX5BEGODmxg", 
oauth_nonce="XXXXX2c525ea3d3f86edfb", 
oauth_signature="b%2BpXXXXXXeC64%3D", 
oauth_signature_method="HMAC-SHA1", 
oauth_timestamp="1395304198", 
oauth_token="2280434016-BXXXXXXXXXXXXKgFautX3LVG", 
oauth_version="1.0"' --verbose

Curl命令从php代码(不同的键,但问题不会改变,当我使用相同的键作为我的dev.twitter.com应用程序:)

curl --get 'https://stream.twitter.com/1.1/statuses/sample.json' --header 'Authorization: OAuth 
oauth_consumer_key="XXXXXT0ayBaTgZ2w", 
oauth_nonce="XXXXXXe8558d961bd398f1", 
oauth_signature="%2FXXXXXXeMUBj%2B2%2Bo%3D", 
oauth_signature_method="HMAC-SHA1", 
oauth_timestamp="1395304620", 
oauth_token="461014117-xXXXXXXXo0104sjmIV053U3e", 
oauth_version="1.0" ' --verbose

谁能告诉为什么一个从PHP代码不会工作?

更新:忘记提及我的TwitterOAuth设置:

$connection = new TwitterOAuth($consumer_key, $consumer_secret, $oauth_access_token, $oauth_access_token_secret);
$connection->timeout = $timeout;
$connection->ssl_verifypeer = false;
$connection->decode_json = false;
if($postfields !== false)
    return $connection->post($url, $postfields, $file);
else
    return $connection->get($url, $getfield, $file);

您正在推--header-H参数下的所有内容。一个一个地使用。像这样:

-H "Authorization: OAuth"
-H "oauth_nonce: XXXXXXe8558d961bd398f1"
-H "oauth_timestamp: 1395304620"

…服务器的系统时钟不同步(几分钟后),所以在将其设置回此时此地后,请求又开始工作了。

最新更新