Gmail API的监控请求未能正常工作

4

有许多关于此主题的文章,但仍然没有确切的解决方法来解决此问题。

即使在下面的Google API链接中,也有一个测试API的选项 https://developers.google.com/gmail/api/v1/reference/users/watch

这个API会抛出一个错误,如无效的主题名称不匹配,但我已经在pub sub中创建了主题,并且已经发布了消息到它上面,那个主题运行得很好,但是我仍然收到以下错误。我收到400错误

{ "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/*" }}

我已经尝试在客户端调用此API,如下所示:
gapi.client.gmail.users.watch({
    'userId': 'me',
     "topicName": "projects/fast-metric-178608/topics/Test" 
  }).then(function (response) { 
        console.log(response) 
  });

以下是输出,我收到了403错误。
{ "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." }}

您之所以收到400错误,是因为您正在使用API浏览器。正如相关的SO帖子中所述,不要像其他帖子中建议的那样使用API浏览器进行测试。您可以按照指南(使用自己的服务账户客户端)中所说的使用Cloud Pub/Sub调用。 - Mr.Rebot
最后,请检查您是否已按照此帖子论坛中所述正确授予了服务帐户在Pub/Sub中发布的权限。 - Mr.Rebot
感谢回复,我已创建服务帐号并将clientId作为参数传递给身份验证方法。var clientId = '89989545454-xyz.apps.googleusercontent.com';function checkAuth() { gapi.auth.authorize({ client_id: clientId, scope: scopes, immediate: true }, handleAuthResult); } - Raj T
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接