【问题标题】:Using additional Google APIs in my Glassware (Sharing to g+ accounts)在我的 Glassware 中使用其他 Google API(分享到 g+ 帐户)
【发布时间】:2013-08-13 15:47:14
【问题描述】:

我正在尝试使用 python 和 Python Mirror API Quickstart 代码从我的 Glassware 共享一张卡片(其中的 html)。

creds = StorageByKeyName(Credentials, '#####', 'credentials').get()
        plus_service = util.create_service('plus', 'v1', creds)

        moment = {"type":"http://schemas.google.com/AddActivity",
        "target": {
        "id": "target-id-1",
        "type":"http://schemas.google.com/AddActivity",
        "name": "The Google+ Platform",
        "description": "A page that describes just how awesome Google+ is!",
        "image": "https://developers.google.com/+/plugins/snippet/examples/thing.png"
                }
        }
        google_request = plus_service.moments().insert(userId='me', collection='vault', body=moment)
        result = google_request.execute()

我收到了回复:

HttpError: <HttpError 403 when requesting https://www.googleapis.com/plus/v1/people/me/moments/vault?alt=json returned "Insufficient Permission">

我可以理解这是一个权限问题,但我的问题是,向 Glass 用户询问 G+ 权限的建议 UI 是什么?

此外,通过在请求的权限中添加“https://www.googleapis.com/auth/plus.login”,我得到了: https://www.googleapis.com/plus/v1/people/me/moments/vault?alt=json 返回“未授权”>

提前致谢

【问题讨论】:

  • 这里有几件事令人困惑,我不完全确定发生了什么。您能否在请求权限的位置显示代码并准确验证您请求的范围?您是否已验证您实际上已获得授权?您具体使用的是哪个启动项目 - 您提到了 Google+ 和 Glassware,它们都有自己的示例代码集。

标签: python google-plus google-mirror-api


【解决方案1】:

要获得 G+ 访问权限,您可以搭载 Mirror API 使用的授权过程。对Mirror API Python Quickstart项目进行如下修改:

首先,在Google API Console 中为您的项目启用 Google+ API。

其次,在oauth/hander.py 中,将您的 G+ 范围添加到 SCOPES 列表:

SCOPES = ('https://www.googleapis.com/auth/glass.timeline '
          'https://www.googleapis.com/auth/glass.location '
          'https://www.googleapis.com/auth/userinfo.profile '
          'https://www.googleapis.com/auth/plus.login')

第三,撤销旧的授权令牌并获得新的。通过退出并重新登录到您的 Quickstart 实例的 Web 前端来执行此操作。当您登录时,登录页面应该会更新以列出新的 Google+ 权限:

通过这些步骤,您发布的代码应该可以正常工作。如果没有,请发表评论,我可以帮助您继续调试。

【讨论】:

  • 还需要注意的是,对于 moment.insert 请求,您需要一个额外的 request_visible_actions 参数来表示要在身份验证期间编写的活动类型,我不确定它如何与 @ 结合使用987654332@。请参阅developers.google.com/+/web/app-activities/… 并将代码示例切换到 Python 以查看如何在其中完成的示例。
  • 更新:您应该能够在示例的第 42 行创建附加参数后立即使用 flow.params["request_visible_actions"] = "http://schemas.google.com/AddActivity" 简单地定义它:github.com/googleglass/mirror-quickstart-python/blob/master/…
  • 我没有再报错,实际结果是: {u'id': u'Eg0xMzc2NTgxOTMyODQ4GJXv34n_2r7nKTICEBRCBxi-ptG5vw1KEPJcM5xKZRfHSKJ91sYVeyA', u'kind': u'plus#moment', u'type': u 'schemas.google.com/AddActivity', u'target': {u'name': u'Google+ 平台', u'kind': u'plus#itemScope', u'id': u'target-id-1', u'image': u'developers.google.com/+/plugins/snippet/examples/thing.png', u'description': u'描述 Google+ 有多棒的页面!'}, u'result': {u'kind': u'plus#itemScope'} } 但我无法在我的个人资料中看到该活动。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-31
  • 1970-01-01
  • 2017-08-13
  • 2014-07-17
  • 1970-01-01
  • 2018-07-26
相关资源
最近更新 更多