2013-03-01 52 views
1

使用新的Twitter API執行用戶搜索時(可在此檢查https://dev.twitter.com/console),發現限制返回結果數量以及分頁。 所以,讓我們說,我想從搜索和使用次數參數得到5個結果:使用API​​ 1.1的Twitter用戶搜索:限制結果和分頁的數量

https://api.twitter.com/1.1/users/search.json?q=Online&count=5

它工作正常,返回5個記錄。但是,如果我設置計數爲零,還有一個返回結果:

https://api.twitter.com/1.1/users/search.json?q=Online&count=0

難道正常嗎?

然後我試圖使用分頁爲同一目的(希望得到的第一頁,並在它極限的結果):

https://api.twitter.com/1.1/users/search.json?q=Online&per_page=5&page=1

現在看起來極限沒有按」根本不工作,返回的記錄多於5條。 有人知道如果查詢出了問題,或者它是一個API錯誤?

回答

1

**嘗試這樣的:** https://api.twitter.com/1.1/users/search.json

參數:

1)頁:指定

頁面

2)count:每頁檢索的用戶結果數量,最多爲20個。

下面的例子將2頁返回1個與搜索關鍵字 「WordPress的」

<?php 
require_once('api/TwitterAPIExchange.php'); 
require_once("token.php"); // For your access token - viral 

$searchword = "wordpress"; 

$url = 'https://api.twitter.com/1.1/users/search.json'; 
$getfield = '?&page=2&count=1&q='.$searchword; 

$requestMethod = 'GET'; 
$twitter = new TwitterAPIExchange($settings); 
$followers = $twitter->setGetfield($getfield) 
    ->buildOauth($url, $requestMethod) 
    ->performRequest(); 

$json = json_decode($followers, true); 

print_r($json); 

?>