2014-08-28 253 views
1

我已經使用Bing圖像API下面的代碼來搜索圖像。但代碼只有50個結果。我怎樣才能獲得更多的結果?如何從Bing搜索API獲得超過50個結果?

$acctKey = 'Account key here'; 
$rootUri = 'https://api.datamarket.azure.com/Bing/Search'; 
$query = 'Kitchen'; 
$serviceOp = 'Image'; 
$market ='en-us'; 
$query = urlencode("'$query'"); 
$market = urlencode("'$market'"); 
$requestUri = "$rootUri/$serviceOp?\$format=json&Query=$query&Market=$market"; 
$auth = base64_encode("$acctKey:$acctKey"); 
$data = array( 
      'http' => array(
         'request_fulluri' => true, 
         'ignore_errors' => true, 
         'header' => "Authorization: Basic $auth" 
         ) 
      ); 
$context = stream_context_create($data); 
$response = file_get_contents($requestUri, 0, $context); 
$response=json_decode($response); 
echo "<pre>"; 
print_r($response); 
echo "</pre>"; 
+1

可能的[Bing API v1文檔]重複(http://stackoverflow.com/questions/15244280/bing-api-v1-documentation) – 2014-08-28 05:52:14

+0

不完全是重複的,但它解釋說您只能得到50個結果查詢,但您可以使用'skip'參數指定從何處開始(這樣您可以使多個查詢構建一個更大的結果集) – 2014-08-28 05:52:45

+0

當我使用$ requestUri的跳過參數。=「&$ skip = 50 「這是返回空結果 – 2014-08-28 06:08:24

回答

0

你應該追加與$頂部您的請求= 50 & $跳過= 0獲得前50個結果,用$頂部= 50 & $跳過= 51,以獲得未來50個結果,這是更好地創建API密鑰以獲取第二個請求,因爲Bing允許每秒處理1次事務,並且如果您超出了限制,您可能會收到此消息錯誤:「503訂閱的每分鐘請求數 已達到允許的最大閾值。