簡體   English   中英

Google自定義搜索JSON API

[英]Google Custom Search JSON API

我正在使用自定義搜索引擎(CSE)通過JSON API玩Google Custom Search API。 我成功獲得了搜索結果,但我對如何獲取nextPageToken一無所知。

https://www.googleapis.com/customsearch/v1?key=MY_API_KEY&cx=MY_SEARCH_ENGINE_ID&q=Testing

JSON響應如下:

{
 "kind": "customsearch#search",
 "url": {
  "type": "application/json",
  "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json"
 },
 "queries": {
  "nextPage": [
   {
    "title": "Google Custom Search - Testing",
    "totalResults": "2900",
    "searchTerms": "Testing",
    "count": 10,
    "startIndex": 11,
    "inputEncoding": "utf8",
    "outputEncoding": "utf8",
    "safe": "off",
    "cx": "MY_SEARCH_ENGINE_ID"
   }
  ],
  "request": [
   {
    "title": "Google Custom Search - Testing",
    "totalResults": "2900",
    "searchTerms": "Testing",
    "count": 10,
    "startIndex": 1,
    "inputEncoding": "utf8",
    "outputEncoding": "utf8",
    "safe": "off",
    "cx": "MY_SEARCH_ENGINE_ID"
   }
  ]
 },
 "context": {
  "title": "Test Search Engine"
 },
 "searchInformation": {
  "searchTime": 0.299265,
  "formattedSearchTime": "0.30",
  "totalResults": "2900",
  "formattedTotalResults": "2,900"
 },
 "items": [
  // ... Search Result here
 ]
}

但如何通過nextPageToken獲取下一頁的結果?

而不是使用nextPageToken ,我可以在查詢字符串中添加2個參數來更改結果頁面:

  • start :結果的起始索引,有效值為整數> 0。
  • num :每頁結果數,有效值為1~10(1頁最多可記錄10條記錄)

因此,要更改為第2頁,我必須發出:

start=11&num=10

在查詢字符串中(假設每頁的記錄數為10)。

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM