OAuth Google People API 刷新令牌不适用于 python 中的联系人范围

问题描述 投票:0回答:1

我使用 oauth 和以下范围获取访问和刷新令牌:

const scopes = [
  "https://www.googleapis.com/auth/calendar",
  "https://www.googleapis.com/auth/contacts.readonly",
  "https://www.googleapis.com/auth/contacts.other.readonly",
];

之前我只使用日历范围,并且访问令牌过期之前和之后一切都正常。当我集成联系人和其他联系人范围时,我能够获取访问令牌和刷新令牌,并向日历和人员 API 发出成功的请求。

但是现在(使用联系人范围)在访问令牌过期后,我收到此错误:

<HttpError 403 when requesting https://people.googleapis.com/v1/people:searchContacts?pageSize=5&query=sofia&readMask=names%2CemailAddresses&alt=json returned "Request had insufficient authentication scopes.". Details: "[{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'ACCESS_TOKEN_SCOPE_INSUFFICIENT', 'domain': 'googleapis.com', 'metadata': {'method': 'google.people.v1.PeopleService.SearchContacts', 'service': 'people.googleapis.com'}}]">

在我的Python逻辑中,令牌实际上被刷新了。打印“刷新后到达”打印,并且在数据库中更新后打印“CREDS AND ACCESS TOKEN WERE UPDATED on host”。

creds = get_google_creds_simple_helper(google_calendar_tokens)
print(creds.valid, 'creds.valid')

if not creds.valid:
    if creds and creds.expired and creds.refresh_token:
        print('got to BEFORE REFRESH')
        try:
            creds.refresh(Request())
        except Exception as e:
            print('Error refreshing credentials:', e)
        print('got to after refresh')
        google_calendar_tokens["token"] = creds.token
        host.google_calendar_tokens = google_calendar_tokens
        host.save()
        print('CREDS AND ACCESS TOKEN WERE UPDATED on host')
return creds

可能出了什么问题?

python google-oauth google-calendar-api google-people-api
1个回答
0
投票

不知道你是否已经解决了这个问题,但我遇到了同样的问题。 对我来说,删除以下解决方案中提到的访问令牌是有效的。

https://stackoverflow.com/a/65336629

© www.soinside.com 2019 - 2024. All rights reserved.