【发布时间】:2016-05-31 22:45:28
【问题描述】:
我正在使用必应搜索 API 来查找诸如公司推特之类的 URL。使用一段时间后,无论我如何更改查询或格式,它都会开始返回:
array(1) {
["d"]=>
array(1) {
["results"]=>
array(0) {
}
}
}
我没有更改获取请求的代码。这是我正在使用的查询:
Capital University%20twitter
这是我用来调用 API 的代码:
$key = 'mykey';
$client = new BingClient($key,'json');
$result = $client->get('Web',['Query' => $query]);
return json_decode($result,true );
我不受速率限制。也许其他人以前遇到过这个问题?
编辑:它现在返回结果(我没有更改代码),但唯一的结果是这个堆栈溢出帖子。第一个字符串是查询,第一个对象是结果。
string(28) "Capital University%20twitter"
object(stdClass)#1008 (1) {
["d"]=>
object(stdClass)#1013 (1) {
["results"]=>
array(1) {
[0]=>
object(stdClass)#1014 (6) {
["__metadata"]=>
object(stdClass)#1015 (2) {
["uri"]=>
string(111)"https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Web?Query='Capital University twitter'&$skip=0&$top=1"
["type"]=>
string(9) "WebResult"
}
["ID"]=>
string(36) "4d5c4ee7-e5f8-44ac-90b3-a12c321e6033"
["Title"]=>
string(59) "PHP Bing Search API returns an empty array - Stack Overflow"
["Description"]=>
string(161) "Capital University%20twitter. And this is the code I use to call the API: $key = 'mykey'; $client = new BingClient($key,'json'); $result = $client->get ('Web ..."
["DisplayUrl"]=>
string(67) "stackoverflow.com/questions/37556866/php-bing-search-api-returns..."
["Url"]=>
string(86) "http://stackoverflow.com/questions/37556866/php-bing-search-api-returns-an-empty-array"
}
}
}
}
string(29) "Capital University%20facebook"
object(stdClass)#1008 (1) {
["d"]=>
object(stdClass)#1016 (1) {
["results"]=>
array(0) {
}
}
}
【问题讨论】:
-
您不需要时常重新生成访问API密钥吗?许多像这样的 API 服务只会在特定时间段(通常是几分钟)内持有有效密钥。
-
好主意 - 但是我的密钥没有改变。
-
嗨@Rob - 好名字,顺便说一句 - 请尽量不要在你的帖子中使用脏话。谢谢!