主题是在云发布/订阅上创建的,但无法在该主题上创建监视 [英] Topic is created on cloud pub/sub but unable to create watch on that topic

查看:20
本文介绍了主题是在云发布/订阅上创建的,但无法在该主题上创建监视的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在云发布/订阅主题上创建手表,但无法创建.为此,我正在使用其余请求

I want to create watch on cloud pub/sub topic but unable to create it. For that I'm using the rest request

request_Req.post({

url:'https://www.googleapis.com/gmail/v1/users/me/watch',
headers:{
   'content-type': 'application/json',
   'Authorization': 'Bearer '+ access_token,
},
scope : [
    'https://mail.google.com/'
],

'body': JSON.stringify({
    'topicName' : "/projects/ProjectId/topics/TopicId",
    'labelIds' : ["INBOX"] 
});
}),function(error, resp, body){

});

但是我收到错误消息 Error sent test message to CloudPubSub/projects/ProjectID/topics/TopicId:找不到资源 resource=TopicId

推荐答案

Google Cloud Pubsub 主题必须存在于同一个用于验证用户身份的 Google Console 项目中.在 Google 控制台中检查/projects/ProjectId/topics/TopicId 您的项目并确保 Pubsub 主题存在.此外,您必须授予对 Gmail 服务的访问权限,才能通过以下请求将消息发布到您的 Pubsub 主题:

The Google Cloud Pubsub topic must exist in the same Google Console project, which is being used to authenticate the users. Check /projects/ProjectId/topics/TopicId your project in Google Console and make sure the Pubsub Topic exists. Also, you must grant access to Gmail services to publish messages to your Pubsub topic via following request:

POST "https://pubsub.googleapis.com/v1beta2/{resource=/projects/**ProjectId**/topics/**TopicId**}:setIamPolicy"
Content-type: application/json

{
  "policy": {
    "bindings": [{
      "role": "roles/pubsub.publisher",
      "members": ["serviceAccount:gmail-api-push@system.gserviceaccount.com"],
    }],
  }
}

如果没有授予 gmail 将消息发布到 Pubsub 主题的权限,则不会创建监视请求.尝试使用 API explorer 设置权限.

If gmail is not granted the access to publish the message to Pubsub topic, watch request wont be created. Try API explorer to set the permissions.

这篇关于主题是在云发布/订阅上创建的,但无法在该主题上创建监视的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆