Twitter Stream API - 401 Unauthorized

自作多情 提交于 2021-02-07 04:20:50

问题


I can't open a connection with Twitter Stream API. The only response I can get, no matter what I try, is 401 Unauthorized.

I've made all kinds of tests, even using some libraries I've found on GitHub.

Even outside my code, using cURL, I can't make it work.

$oauth = array( 
    'oauth_consumer_key' => $this->m_oauth_consumer_key,
    'oauth_nonce' => time(),
    'oauth_signature_method' => 'HMAC-SHA1',
    'oauth_token' => $this->m_oauth_token,
    'oauth_timestamp' => time(),
    'oauth_version' => '1.0'
);

$base_info = $this->buildBaseString($this->url, 'GET', $oauth);
$composite_key = rawurlencode($this->m_oauth_consumer_secret) . '&' . rawurlencode($this->m_oauth_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
$header = $this->buildAuthorizationHeader($oauth);

This is my code for building HTTP Request Header and Signature. I've tried in a lot of different ways, no success.

Anoyone have any ideia that could help me?

Thank you in advance.


回答1:


If you're on Linux, sync your time with an NTP server:

$ sudo ntpdate ntp.org



回答2:


I was trying to access the API today with node.js and had the same error. My Windows didn't yet update my clock, so my local computer time was off by an hour(daylight saving time switch was today). When I changed it, it started to work again. They should really have some better error message than just plain 401.




回答3:


I had the same problem. Go to your App Settings screen and change Callback URL to something like yoursite.com. I'm not sure why but once you change that you won't see 401 error anymore.



来源:https://stackoverflow.com/questions/20594173/twitter-stream-api-401-unauthorized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!