【问题标题】:Is app_identity.get_access_token supposed to work in development environment?app_identity.get_access_token 应该在开发环境中工作吗?
【发布时间】:2014-05-20 04:47:58
【问题描述】:

我使用this code 从我的 GAE 应用程序访问 Google API:

scope = "https://www.googleapis.com/auth/urlshortener"
authorization_token, _ = app_identity.get_access_token(scope)

它适用于生产环境,但不适用于开发环境:

Using token InvalidToken:https://www.googleapis.com/auth/urlshortener:77.5780799389 to represent identity test@localhost
('Call failed. Status code %s. Body %s', 401L, '{\n "error": {\n  "errors": [\n   {\n    "domain": "global",\n    "reason": "authError",\n    "message": "Invalid Credentials",\n    "locationType": "header",\n    "location": "Authorization"\n   }\n  ],\n  "code": 401,\n  "message": "Invalid Credentials"\n }\n}\n')

我可以应用任何解决方法(但不能从头开始实施 OAuth)吗?

更新。从开发环境访问 Google API 的另一种方法也不起作用:

credentials = AppAssertionCredentials(scope='https://www.googleapis.com/auth/analytics.readonly')
http = credentials.authorize(httplib2.Http(memcache))
service = build('analytics', 'v3', http=http)
response = service.management().accounts().list().execute()
logging.info(response)

【问题讨论】:

    标签: google-app-engine google-api google-oauth


    【解决方案1】:

    实际上,dev_appserver.py 最近添加了一些参数以使 appidentity 在本地测试期间工作。详情请见Unable to access BigQuery from local App Engine development server

    【讨论】:

    • 非常感谢,效果很好! (认为​​它不起作用,但一段时间后它开始运行良好 - 看起来需要一些时间才能在 Google 方面授予所有权限)
    【解决方案2】:

    它在 appspot.com 上运行的原因是因为它使用了自动创建的 App Engine 服务帐户。由于服务帐户与运行它的应用引擎实例相关联,因此可以保证其权限。当您在本地运行时,没有服务帐户 - 他们怎么知道您正在调试自己的应用程序而不是其他人的应用程序?

    如果你想在本地运行你的代码,你需要实现 OAuth,实际上这只是几行代码。

    【讨论】:

    猜你喜欢
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-16
    相关资源
    最近更新 更多