【问题标题】:How can I use the OAuth2Decorator with Google Cloud Storage?如何将 OAuth2Decorator 与 Google Cloud Storage 一起使用?
【发布时间】:2011-11-30 11:24:51
【问题描述】:

我关注这个instructions 是为了将我的应用引擎python web 服务与谷歌存储连接起来,特别是能够使用文件API。我经历了嗡嗡声的例子,但似乎对我不起作用。我需要 Web 服务在后台进行授权,以便能够从存储中检索我的文件。

我正在尝试使用装饰器来传递我的 client_id 和 client_secret,但这个过程对我来说不是很清楚。谁能提供一个例子或详细说明这个过程?

编辑:我使用的是 python 2.7 运行时。

【问题讨论】:

  • “它似乎不起作用”没有帮助。您尝试了什么,发生了什么?

标签: python google-app-engine google-api-python-client google-cloud-storage


【解决方案1】:

这可能不是最直接的答案,但您是否探索过 App Engine 上内置的 Google Storage API?

http://code.google.com/appengine/docs/python/googlestorage/

这让您可以一起绕过原生 API。

【讨论】:

  • 是的,并且使用 App Identity 您不需要进行 OAuth。
【解决方案2】:

我通过使用来自au-to-do google appengine 项目的 gslite.py 脚本和我的凭据设法让它正常运行。

【讨论】:

    【解决方案3】:

    如果您将 apiclient 与本机 REST API 一起使用,它看起来像这样......

    from apiclient.discovery import build
    import httplib2
    from oauth2client.appengine import OAuth2Decorator
    
    decorator = OAuth2Decorator(client_id=YOUR_GOOGLE_CLIENT_ID,
                                client_secret=YOUR_GOOGLE_CLIENT_SECRET,
                                scope=GOOGLE_SERVICE_SCOPE,
                                )
    
    class MainHandler(webapp.RequestHandler):
    
       @decorator.oauth_required
       def get(self):
        service = build(SERVICE_NAME, 
                        SERVICE_VERSION,
                        http=decorator.http())
        magic = service.method()
    

    查看其他 API 的一些 apiclient 示例可能会有所帮助。例如,有一个 App Engine 与同样使用 OAuth2 的 Tasks API 集成的好例子。

    http://code.google.com/appengine/articles/python/getting_started_with_tasks_api.html

    【讨论】:

    • 但是您仍然可以从装饰器中检索访问令牌,并将其与 REST API 一起使用(请参阅 decorator.credentials.access_token 和 decorator.credentials.refresh_token)。
    猜你喜欢
    • 2017-03-21
    • 1970-01-01
    • 2019-05-12
    • 1970-01-01
    • 2014-11-05
    • 2021-02-21
    • 2019-12-29
    • 1970-01-01
    • 2019-05-18
    相关资源
    最近更新 更多