我尝试使用 OAuth2 构建具有以下内容的组设置服务:
def groupSettingsService(request):
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')
FLOW = client.flow_from_clientsecrets(CLIENT_SECRETS, scope=['https://www.googleapis.com/auth/apps.groups.settings'], message=tools.message_if_missing(CLIENT_SECRETS))
storage = Storage('groups-settings.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = run(FLOW, storage)
http = httplib2.Http()
http = credentials.authorize(http)
return discovery.build('groupssettings', 'v1', http=http)
但问题是,当令牌不再有效(过期)时,它会重定向到一个页面,告诉用户再次授予对该范围的访问权限……不适合 API 调用的事情!
有没有办法使用用户名/密码或 client_secret 来永久授予对 API 的完全访问权限而不要求授予访问权限?