【发布时间】:2021-12-13 07:36:58
【问题描述】:
我已经构建了一个 django 应用程序,其中包括 google Oauth2.0 登录。 我想在每个用户使用 Oauth2.0 登录时获取他们的谷歌日历事件,我编写了以下代码。我将访问令牌保存到 UserAuth 表中并获取它,然后用它来获取谷歌日历。
def get_events_server(request):
user = User.objects.get(username=request.user)
creds = UserAuth.objects.get(user=user).google_id_token
credentials = AccessTokenCredentials(creds, "")
http = httplib2.Http()
http = credentials.authorize(http)
service = build('calendar', 'v3', http=http)
return service
当我运行代码时,发生了以下错误。
HttpError at /calendar/
<HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/primary/events?timeMin=2021-10-28T04%3A33%3A08.956703Z&timeMax=2021-11-04T04%3A33%3A08.956712Z&singleEvents=true&timeZone=GMT%2B9%3A00&orderBy=startTime&alt=json returned "Request had insufficient authentication scopes.". Details: "[{'message': 'Insufficient Permission', 'domain': 'global', 'reason': 'insufficientPermissions'}]">
【问题讨论】:
-
您能否提供更多有关您如何获得访问令牌的信息?为了获得它们,用户是否以自己的身份进行身份验证?如果您通过身份验证获得它,则访问令牌将只能访问您的帐户可以访问的事件。
-
是的,用户将使用他们的谷歌帐户登录,如 Oauth 登录,他们将获取他们的访问令牌。
标签: python django google-oauth google-calendar-api google-signin