简体   繁体   English

主题是在云pub / sub上创建的,但无法在该主题上创建监视

[英]Topic is created on cloud pub/sub but unable to create watch on that topic

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){

});

But I'm getting the error message Error sending test message to Cloud PubSub/projects/ProjectID/topics/TopicId : Resource not found resource=TopicId 但我收到错误消息Error sending test message to Cloud PubSub/projects/ProjectID/topics/TopicId : Resource not found resource=TopicId

The Google Cloud Pubsub topic must exist in the same Google Console project, which is being used to authenticate the users. Google Cloud Pubsub主题必须存在于同一Google Console项目中,该项目用于对用户进行身份验证。 Check /projects/ ProjectId /topics/ TopicId your project in Google Console and make sure the Pubsub Topic exists. 在Google Console中检查/ projects / ProjectId / topics / TopicId您的项目并确保存在Pubsub主题。 Also, you must grant access to Gmail services to publish messages to your Pubsub topic via following request: 此外,您必须授予对Gmail服务的访问权限,才能通过以下请求将消息发布到您的Pubsub主题:

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"],
    }],
  }
}

If gmail is not granted the access to publish the message to Pubsub topic, watch request wont be created. 如果未授予gmail将消息发布到Pubsub主题的权限,则不会创建监视请求。 Try API explorer to set the permissions. 尝试使用API资源管理器来设置权限。

Make sure the topic is created AND make sure you've correctly setIamPolicy on it. 确保创建主题并确保在其上正确设置了AnyPolicy。 Do NOT use API explorer on it as advised by other answer. 根据其他答案的建议,请勿在其上使用API​​资源管理器。 Do those Cloud Pub/SUb calls as it says in the guide (using your own service-account client) : https://developers.google.com/gmail/api/guides/push 按照指南中的说明(使用您自己的服务帐户客户端)执行这些Cloud Pub / SUb呼叫: https//developers.google.com/gmail/api/guides/push

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM