【发布时间】:2016-10-12 04:12:59
【问题描述】:
我正在获取用户的推文。我需要显示所有带有 ajax 分页的推文。我怎样才能做到这一点?
https://api.twitter.com/1.1/statuses/user_timeline.json
试过
我正在使用上面的链接。我听说过max_id、since_id,但不知道如何使用。我试过max_id 和since_id,然后收集重复。我没有得到任何光标响应。
我的代码
$api_key = urlencode('*********'); // Consumer Key (API Key)
$api_secret = urlencode('***********'); // Consumer Secret (API Secret)
$auth_url = 'https://api.twitter.com/oauth2/token';
// what we want?
$data_username = '********'; // username
$data_count = 1; // number of tweets
$data_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
// get api access token
$api_credentials = base64_encode($api_key . ':' . $api_secret);
$auth_headers = 'Authorization: Basic ' . $api_credentials . "\r\n" .
'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' . "\r\n";
$auth_context = stream_context_create(
array(
'http' => array(
'header' => $auth_headers,
'method' => 'POST',
'content' => http_build_query(array('grant_type' => 'client_credentials',)),
)
)
);
$auth_response = json_decode(file_get_contents($auth_url, 0, $auth_context), true);
$auth_token = $auth_response['access_token'];
// get tweets
$data_context = stream_context_create(array('http' => array('header' => 'Authorization: Bearer ' . $auth_token . "\r\n",)));
$datas = json_decode(file_get_contents($data_url . '?include_rts=true&count=' . $data_count . '&screen_name=' . urlencode($data_username), 0, $data_context), true);
// result - do what you want
print('<pre>');
print_r($datas);
问题
我必须传递哪些值才能获取分页 url?
谢谢。
【问题讨论】:
-
请发布您的示例代码。
-
任何人都知道解决方案吗?
标签: php json twitter twitter-oauth