通过 OAuth 2.0 使用服务帐户调用 v3 Google Calendar API 时出现 403 禁止消息 [英] 403 Forbidden message when calling the v3 Google Calendar API using a Service Account via OAuth 2.0
问题描述
这是我关于使用 Google Calendar API 和 OAuth2 时出现 401 错误的后续帖子,可在 此处
这包含导致我的下一个问题的帐户设置的详细信息,因此我不会在此线程中重复自己.
好的,所以当我调用以下代码更新日历事件时,我收到 403 禁止错误.
for (Event event : events.getItems()){event.setSummary("XXX" + event.getSummary());事件更新事件 = calendar.events().update(CALENDAR_ID, event.getId(), event).execute();}
这是返回的错误信息:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden{代码":403,错误":[{消息":禁止"}],消息":禁止"}
我尝试了什么?好吧,我重新阅读了有关服务帐户的(相当糟糕的)Google 文档,重新检查了我的 API 控制台帐户设置,尝试更改构建凭证的代码(这会导致其他错误,因此是我之前线程的回归).
简而言之,没有任何作用,所以我有什么明显的遗漏吗?
已解决,感谢这篇帖子.>
您必须将您的 Google 日历帐户中的日历与在 Google API 控制台中生成的服务帐户电子邮件共享,例如284XXXXXXXX@developer.gserviceaccount.com.
我现在可以从我的网络服务更新我的日历.
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 Calendar API 时出现 403 禁止消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!