【问题标题】:google plus API shows less activities than sitegoogle plus API 显示的活动少于站点
【发布时间】:2012-08-17 08:57:21
【问题描述】:

我使用 maxResults=8 的 API 调用仅返回 6 个项目,而在 googleplus 网站搜索中显然有更多结果。
此外,当将最大结果设置为 20 时,我会得到更多结果。

那么为什么我只收到六件物品,而可能有八件?

我的电话:
https://www.googleapis.com/plus/v1/activities?query=gamescon&key=mykey&orderBy=recent&maxResults=8&fields=items(actor(displayName),kind,object(attachments(content,image(type,url),url),content,objectType),published,title,url,verb)

【问题讨论】:

    标签: google-plus


    【解决方案1】:

    Google+ API 保证响应中的项目数不会超过请求的maxResults,但不保证响应中有很多结果。如果nextPageToken 字段在结果的第一页中可用,则将其用于另一页结果。

    您需要在 JSON 响应中捕获 nextPageToken 字段。获取此页面令牌,并使用该 pageToken 发出另一个请求。

    例如,请求:

    https://www.googleapis.com/plus/v1/activities?query=gamescon&key=mykey&orderBy=recent&maxResults=8&fields=nextPageToken,items

    回复:

    {
     "nextPageToken": "xyz",
     "items": [
       ...
     ]
    }
    

    在该响应中获取nextPageToken,并将其作为pageToken 查询参数包含在您的下一个请求中。

    https://www.googleapis.com/plus/v1/activities?query=gamescon&key=mykey&orderBy=recent&maxResults=8&pageToken=xyz&fields=nextPageToken,items

    【讨论】:

    • 好吧,我想我只是设置了 maxResults 并稍后限制它,感谢您的回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-04
    相关资源
    最近更新 更多