我想在 PHP、JS 或 ObjC 中使用 Bing IMAGE API,但类和属性如 http://msdn.microsoft.com/en-us/library/dd250939.aspx 似乎只能在 C# 或 VB 中使用,是吗?
我只想获取图像搜索 JSON 结果,指定宽度和高度... 从 GET url 看来不可能: api.bing.net/xml.aspx?Appid=XXXXXXXXXXXXXXXXXXXXX&query=sushi&sources=image 我尝试插入 &size=small 或 &width=300,但没有发回任何更改。
我可以使用 ObjC iOS 和 http://ibing.codeplex.com/ 的 API确实实现了 WIDTH 和 HEIGHT 属性,但只是作为响应信息,而不是请求参数。
最佳答案
这就是我的做法:
获取一个 PHP 脚本来在您的服务器上完成这项工作(这对我来说适用于常规 API 搜索,但也应该适用于图像搜索(也许需要进行一些修改......)):
function getOnePageUrls($querystr, $country="com", $page=1) { $markets = array( "com" => "en-US", "co.uk" => "en-GB", "ru" => "ru-RU", "de" => "de-DE", "fr" => "fr-FR", "es" => "es-ES" ); $market = $markets[$country]; if ($page==1) $offset = 0; else $offset = (($page-1)*50)+1; $appID = "XXXXXXXXXXXXXXXXXXXXXXXXX"; // your Bing App ID $searchstr = "http://api.search.live.net/json.aspx?Appid=$appID&query=$querystr&sources=web&market=$market&web.count=50&web.offset=$offset"; $json = file_get_contents($searchstr); $results = json_decode($json); $results = $results->SearchResponse->Web->Results; foreach ($results as $result) { $response[] = $result->DisplayUrl; } return $response; }
使用简单的 GET 在 Objective-C 代码中获取响应 请求
就是这样! :-)
关于image - 适用于 iOS 的必应搜索 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9719084/