【问题标题】:get total result from google search using REST to invoke API使用 REST 从谷歌搜索中获取总结果以调用 API
【发布时间】:2011-02-20 16:16:55
【问题描述】:

你好,我做错了。 我想从这个返回的 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;

但我什么都没有。 需要帮助。谢谢。

【问题讨论】:

  • 您是否将密钥插入到INSERT-YOUR-KEY 的位置?
  • 是的,我确实插入了 api 密钥。只是不知道如何只显示总结果;

标签: php google-search-api


【解决方案1】:

在您的帖子中,所有 json 都不可见。在我的测试中,它适用于:

$json->queries->request[0]->totalResults;

【讨论】:

    【解决方案2】:

    也许尝试一个 if(!is_null($json->request->totalResults)) 条件来看看你是否甚至得到响应。

    【讨论】:

    • 我收到一个响应,响应结构模式是 json 格式,类似于这个 url; code.google.com/apis/customsearch/v1/using_rest.htmlcode$json->request->totalResultscode 似乎不起作用。
    • 我从您链接到的 Google 页面抓取了 JSON,这对我有用:code$json->queries->request[0]->totalResults
    • 好的..谢谢。现在我知道如何获得它了。非常感谢@jondbaker
    猜你喜欢
    • 1970-01-01
    • 2014-08-25
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    • 1970-01-01
    • 2016-10-11
    相关资源
    最近更新 更多