4
votes

There are many post on this same topic but still there is no exact solution to solve this issue.

even in the google API below link, there is a option to test the API https://developers.google.com/gmail/api/v1/reference/users/watch

This API throws a error like Invalid Topic Name does not match but I have created the topic in the pub sub and I have published the message on it, that topic works fine but then also I am receiving below error. I am receiving 400 error

{ "error": {"errors": [{
"domain": "global",
"reason": "invalidArgument",
"message": "Invalid topicName does not match projects/google.com:apisexplorerconsole/topics/*"   }  ],"code": 400,"message":"Invalid topicName does not match projects/google.com:apisexplorerconsole/topics/*" }}

I have tried to call this API in client side, like below

gapi.client.gmail.users.watch({
    'userId': 'me',
     "topicName": "projects/fast-metric-178608/topics/Test" 
  }).then(function (response) { 
        console.log(response) 
  });

Below is output , i am receiving 403 error

{ "error": { "errors": [{
"domain": "global",
"reason": "forbidden",
"message": "Error sending test message to Cloud PubSub projects/fast-metric-178608/topics/Test : User not authorized to perform this action."}  ],"code": 403,  "message": "Error sending test message to Cloud PubSub projects/fast-metric-178608/topics/Test : User not authorized to perform this action." }}
1
You are getting 400 error because you are using API explorer. As stated in this related SO post, do not use API explorer to test it as suggested in other post.You can use Cloud Pub/SUb calls as it says in the guide (using your own service-account client). - Mr.Rebot
Lastly, check if you have properly gave your service account permission to post in Pub/Sub as stated in this post and forum. - Mr.Rebot
Thanks for reply , i have created service account and i am passing clientId as param for authentication method var clientId = '89989545454-xyz.apps.googleusercontent.com'; function checkAuth() { gapi.auth.authorize({ client_id: clientId, scope: scopes, immediate: true }, handleAuthResult); } - Raj T

1 Answers

0
votes

https://console.cloud.google.com/cloudpubsub/topicList

select your topic and set your topic PERMISSIONS allUser and Select a role Pub/Sub Admin