【发布时间】:2013-05-27 11:15:20
【问题描述】:
我有一个 Python 程序与 Google API 交互,该程序通过 OAuth 使用 Google 提供的示例代码进行身份验证:
# Perform OAuth 2.0 authorization.
flow = oauth2client.client.flow_from_clientsecrets(
parameters[self.PARAM_SECRETS], scope=self.GCE_SCOPE)
storage = oauth2client.file.Storage(LocalState.get_oauth2_storage_location(
parameters[self.PARAM_KEYNAME]))
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = oauth2client.tools.run(flow, storage)
# Build the service
return apiclient.discovery.build('compute', self.API_VERSION), credentials
但是,每当我运行此程序时,它都会强制打开浏览器并要求用户单击按钮进行身份验证。如果程序在没有本地 Web 服务器的机器上运行,这会导致问题。我看过this question,似乎表明使用--noauth_local_webserver可以解决问题,但它说我必须重写我的程序才能使用gflags进行参数处理,而我现有的代码已经使用@ 987654325@.
有没有一种方法可以在不强制打开浏览器的情况下验证用户身份,而无需重写我的整个应用程序以使用gflags?
【问题讨论】:
标签: python oauth-2.0 google-api-python-client