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

时间:2014-03-20 08:40:33

标签: php curl twitter

我使用自己的代码来生成twitter API的oauth请求,但几天前它停止了工作(我刚才注意到了。)我现在已切换到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):

&#34;测试OAuth&#34; dev.twitter.com上的功能,给我一个的curl命令,所以我改变了PHP代码来输出这样的命令。但是,这不起作用。同样旧的&#39;未经授权的&#39;误差;

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

来自php代码的curl命令(不同的密钥,但当我使用与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);

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

Derp ...服务器的系统时钟不同步(如果进入未来几分钟就会结束)所以在将它设置回到此处之后,请求再次正常工作。