使用REST从谷歌搜索获得总结果来调用API

时间:2011-02-20 16:16:56

标签: php google-search-api

是的,我无法做到这一点。 我想从这个返回的json结果中得到totalResults 全文:http://code.google.com/apis/customsearch/v1/using_rest.html

  "request": [
   {
    "title": "Google Custom Search - flowers",
    "totalResults": 10300000,
    "searchTerms": "flowers",
   }
  ]
 },

我试过这个:

$response = file_get_contents('https://www.googleapis.com/customsearch/v1?key=INSERT-YOUR-KEY&cx=013036536707430787589:_pqjad5hr1a&q=flowers&alt=json
');
$json = json_decode($response);
echo "Total Result:".$json->request->totalResults;

但我一无所获。 需要帮助请。感谢。

2 个答案:

答案 0 :(得分:1)

在你的帖子里,所有的json都看不见了。在我的测试中它适用于此:

  

$ json->查询 - >请求[0] - >使用totalResults;

答案 1 :(得分:0)

也许尝试if(!is_null($ json-> request-> totalResults))条件,看看你是否得到了回复。

相关问题