gpt4 book ai didi

node.js - drive.changes.watch 不发送通知

转载 作者:太空宇宙 更新时间:2023-11-03 23:32:32 25 4
gpt4 key购买 nike

我正在将 googleapis npm 软件包(“apis/drive/v3.js”)用于 Google 云端硬盘服务。在后端,我使用 NodeJSngrok 进行本地测试。我的问题是我无法收到通知。代码如下:

    drive.changes.watch({
pageToken: startPageToken,
resource: {
id: uuid.v1(),
type: 'web_hook',
address: 'https://7def94f6.ngrok.io/notifications'
}
}, function(err, result) {
console.log(result)
});

返回类似:

{
kind: 'api#channel',
id: '8c9d74f0-fe7b-11e5-a764-fd0d7465593e',
resourceId: '9amJTbMCYabCkFvn8ssPrtzWvAM',
resourceUri: 'https://www.googleapis.com/drive/v3/changes?includeRemoved=true&pageSize=100&pageToken=6051&restrictToMyDrive=false&spaces=drive&alt=json',
expiration: '1460227829000'
}

当我尝试更改 Google 云端硬盘中的任何文件时,没有收到通知。亲爱的大学,出了什么问题?

最佳答案

这应该是一条评论,但我没有足够的(50分)经验来发表评论。抱歉,如果这不是真正的答案,但可能会有所帮助。

我今天才知道这一点。我实际上正在做和你一样的事情 - 只是不是使用 Drive,而是使用 Gmail api。我发现你有这个错误:

"push.webhookUrlUnauthorized", "message": "未经授权的 WebHook 等..."

我认为这是因为以下两个原因之一:

  1. 您没有向 Drive-api 发布者授予您主题的权限。

  2. 其次,如果您想接收通知,则必须在服务器(您的项目)和您的 pub/sub 服务(Google Cloud)中设置授权的 webHooks 网址。

见下文 - 对我来说这个设置有效:

1. Create a topic

1. Create a topic

 2. Give the Drive publish permissions to your topic. This is done by adding the Drive scope in the box and following steps 2 and 3.

2. Give the Drive publisher permission to your topic

3. Configure authorized WebHooks. Form the Create Topic page - click on add subscriptions. Not rely vizible here but once you are there you can manage.

3. Configure authorized WebHooks

关于node.js - drive.changes.watch 不发送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36521147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com