简体   繁体   English

使用curl获取Twitter用户时间线

[英]Get Twitter user timeline with curl

I would like to get the Twitter timeline but I'm receiving the error Could not authenticate you","code":32. 我想获取Twitter时间轴,但收到错误“ Could not authenticate you","code":32.

This is my script: 这是我的脚本:

$base = '';
$base .= 'GET';
$base .= '&';
$base .= rawurlencode('https://api.twitter.com/1.1/statuses/user_timeline.json');
$base .= '&';
$base .= rawurlencode($oauth_hash);

$key = '';
$key .= rawurlencode('MY_CONSUMER_SECRET');
$key .= '&';
$key .= rawurlencode('MY_ACCESS_TOKEN_SECRET');

$signature = base64_encode(hash_hmac('sha1', $base, $key, true));
$signature = rawurlencode($signature);

$oauth_header = '';
$oauth_header .= 'oauth_consumer_key="MY_CONSUMER_KEY", ';
$oauth_header .= 'oauth_nonce="' . time() . '", ';
$oauth_header .= 'oauth_signature="' . $signature . '", ';
$oauth_header .= 'oauth_signature_method="HMAC-SHA1", ';
$oauth_header .= 'oauth_timestamp="' . time() . '", ';
$oauth_header .= 'oauth_token="MY_ACCESS_TOKEN", ';
$oauth_header .= 'oauth_version="1.0", ';

$curl_header = array("Authorization: OAuth {$oauth_header}", 'Expect:');
$curl_request = curl_init();

curl_setopt($curl_request, CURLOPT_HTTPHEADER, $curl_header);
curl_setopt($curl_request, CURLOPT_HEADER, false);
curl_setopt($curl_request, CURLOPT_URL, 'https://api.twitter.com/1.1/statuses/user_timeline.json');
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);

$json = curl_exec($curl_request);
curl_close($curl_request);
?>

What do I need to change to make it work? 我需要更改使其工作吗?

Thank you. 谢谢。 Uli 乌里

Have a look a this useful blog post "Working with Twitter's 1.1 API via PHP, OAuth": 看看这篇有用的博客文章“通过PHP,OAuth使用Twitter的1.1 API”:

http://blog.jacobemerick.com/web-development/working-with-twitters-api-via-php-oauth/ http://blog.jacobemerick.com/web-development/working-with-twitters-api-via-php-oauth/

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

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