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

孤街醉人 提交于 2019-12-01 05:06:54

问题


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


回答1:


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

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.




回答2:


Make sure the topic is created AND make sure you've correctly setIamPolicy on it. Do NOT use API explorer on it as advised by other answer. 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



来源:https://stackoverflow.com/questions/30952979/topic-is-created-on-cloud-pub-sub-but-unable-to-create-watch-on-that-topic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!