0
我使用Twitter的API,並試圖獲取使用Twitter的API獲取用戶的timeline帖子是新手。我已經試過這段代碼來實現這一點。Twitter的API不要求用戶訪問權限
它顯示我所有我的帳戶的時間表數據,但不要求用戶權限訪問或登錄憑據在技術上我沒有登錄到我的賬戶,現在仍然是顯示我所有我的帳戶數據。
function buildBaseString($baseURI, $method, $params) {
$r = array();
ksort($params);
foreach($params as $key=>$value){
$r[] = "$key=" . rawurlencode($value);
}
return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
}
function buildAuthorizationHeader($oauth) {
$r = 'Authorization: OAuth ';
$values = array();
foreach($oauth as $key=>$value)
$values[] = "$key=\"" . rawurlencode($value) . "\"";
$r .= implode(', ', $values);
return $r;
}
$url = "https://api.twitter.com/1.1/statuses/home_timeline.json";
$oauth_access_token = "ACCESS TOKEN";
$oauth_access_token_secret = "ACCESS TOKEN SECRET";
$consumer_key = "APP KEY";
$consumer_secret = "APP KEY SECRET";
$oauth = array('oauth_consumer_key' => $consumer_key,
'oauth_nonce' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_token' => $oauth_access_token,
'oauth_timestamp' => time(),
'oauth_version' => '1.0');
$base_info = buildBaseString($url, 'GET', $oauth);
$composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
// Make requests
$header = array(buildAuthorizationHeader($oauth), 'Expect:');
$options = array(CURLOPT_HTTPHEADER => $header,
//CURLOPT_POSTFIELDS => $postfields,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
$twitter_data = json_decode($json);
//print it out
echo "<pre>"; print_r ($twitter_data);
我已經找到了this post
代碼任何幫助將非常感激。
感謝