【问题标题】:Google Drive API V3 - Push NotificationsGoogle Drive API V3 - 推送通知
【发布时间】:2018-05-23 07:02:43
【问题描述】:

从昨天早上开始,我就遇到了一个 google drive API 请求。

如此处所述:https://developers.google.com/drive/api/v3/push

我正在尝试订阅发送此请求的通知:

网址:https://www.googleapis.com/drive/v3/changes/watch

Header :
Content-type: application/json
Authorization: Bearer my_auth_token

{
"id":"An ID generated",
"type":"web_hook",
"address":"my callback address",
}

响应是带有此正文的代码 400:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Required parameter: pageToken",
    "locationType": "parameter",
    "location": "pageToken"
   }
  ],
  "code": 400,
  "message": "Required parameter: pageToken"
 }
}

此订阅请求不需要此参数,但对于此(相同的 url..):https://developers.google.com/drive/api/v3/reference/changes/watch

我是否遗漏/误解了某些内容或文档有问题?

谢谢

【问题讨论】:

    标签: google-api google-drive-api


    【解决方案1】:

    pageToken 参数是在下一页继续上一个列表请求的令牌。这应该设置为来自上一个响应的“nextPageToken”值或来自 getStartPageToken 方法的响应,正如我们看到的here

    因此,您应该将pageToken 作为参数传递给您的网址:

    网址:https://www.googleapis.com/drive/v3/changes/watch?pageToken=[YOUR_PAGE_TOKEN_NUMBER_HERE]

    例如:https://www.googleapis.com/drive/v3/changes/watch?pageToken=101

    使用GET https://www.googleapis.com/drive/v3/changes/startPageToken 获取起始pageToken 用于列出和观察未来变化可能会很有趣。见here

    【讨论】:

    • 感谢您的回复,完美地完成了 Mr.Rebot 的回复
    • 不幸的是我现在有另一个问题。它总是向我显示我正在使用 Postman 和 C Sharp 尝试的未经授权的 WebHook 回调通道
    【解决方案2】:

    您可能会感到困惑,检查documentation,如果您提出监视请求,它应该在此帖子网址下 https://www.googleapis.com/apiName/apiVersion/resourcePath/watch 而不是 https://www.googleapis.com/drive/v3/changes/watch这就是您收到错误“必需参数:pageToken”的原因。

    这是完整的观看请求代码:

    POST https://www.googleapis.com/drive/v3/files/fileId/watch
    Authorization: Bearer auth_token_for_current_user
    Content-Type: application/json
    
    {
      "id": "01234567-89ab-cdef-0123456789ab", // Your channel ID.
      "type": "web_hook",
      "address": "https://yourdom.com/notifications", // Your receiving URL.
      ...
      "token": "target=myApp-myFilesChannelDest", // (Optional) Your channel token.
      "expiration": 1426325213000 // (Optional) Your requested channel expiration time.
    }
    

    首先不要忘记register your domain。希望这会有所帮助。

    【讨论】:

    • 感谢 Rebot 先生的回复。关键是“googleapis.com/drive/v3/changes/watch”被描述为可用于观察所有文件的更改。我希望收到任何修改或创建的文件的通知。
    猜你喜欢
    • 2017-05-31
    • 2017-05-13
    • 2019-03-07
    • 2016-07-31
    • 1970-01-01
    • 2013-07-21
    • 1970-01-01
    • 1970-01-01
    • 2017-07-25
    相关资源
    最近更新 更多