【问题标题】:Using Google Client Library in Python without local webserver在没有本地网络服务器的情况下在 Python 中使用 Google 客户端库
【发布时间】: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


    【解决方案1】:

    好吧,今天它不会帮助你,但是客户端库中对 gflags 的依赖是 being removed 在 1.2 版本中。更新的run() command now uses argparse,通常不会依赖核心库中的任何特定标志库。不幸的是,这并不能为您解决今天的问题。我希望在本月底之前发布 1.2 版本,但不能保证。

    【讨论】:

    • 太棒了,那我就等着吧!
    猜你喜欢
    • 2011-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 2010-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多