当通过OAuth 2.0使用服务帐户调用v3 Google日历API时,出现403禁止消息 [英] 403 Forbidden message when calling the v3 Google Calendar API using a Service Account via OAuth 2.0

查看:96
本文介绍了当通过OAuth 2.0使用服务帐户调用v3 Google日历API时,出现403禁止消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的主题关于使用Google Calendar API和OAuth2时出现401错误的后续操作,可以在

这是返回的错误消息:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
    "code" : 403,
    "errors" : [ {
        "message" : "Forbidden"
     } ],
    "message" : "Forbidden"
}

我尝试了什么?好吧,我已经重新阅读了(相当差劲的)关于服务帐户的Google文档,重新检查了我的API控制台帐户设置,尝试更改了构建证书的代码(这会导致其他错误,因此是我先前线程的回归)

简而言之,什么都没有,所以我有什么明显的遗漏吗?

解决方案

已解决,这要感谢帖子.

您必须将Google日历帐户中的日历与在Google API控制台中生成的服务帐户电子邮件共享,例如 284XXXXXXXX@developer.gserviceaccount.com .

我现在可以从Web服务更新日历.

This is a follow on from my thread about a 401 error when using the Google Calendar API and OAuth2, which can be found here

This contains details of the account setup that leads onto my next question, so I wont repeat myself in this thread.

OK, so when when I call the following code to update a Calendar event I get a 403 forbidden error.

for (Event event : events.getItems())
{
    event.setSummary("XXX" + event.getSummary());

    Event updatedEvent = calendar.events().update(CALENDAR_ID, event.getId(), event).execute();
}

Here is the returned error message:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
    "code" : 403,
    "errors" : [ {
        "message" : "Forbidden"
     } ],
    "message" : "Forbidden"
}

What have I tried? Well, I have re-read the (rather poor) Google documentation about Service Accounts, re-checked my API Console account settings, tried changing the code that builds the credential (this leads to other errors so is a regression on my previous thread).

In short, nothing works, so is there anything obvious I am missing?

解决方案

Solved, thanks to this post.

You have to share the calendar from your Google Calendar account with the Service Account email that is generated in the Google API Console, e.g. 284XXXXXXXX@developer.gserviceaccount.com.

I can now update my calendar from my web service.

这篇关于当通过OAuth 2.0使用服务帐户调用v3 Google日历API时,出现403禁止消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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