Using additional Google APIs in my Glassware (Sharing to g+ accounts)

点点圈 提交于 2019-12-11 04:14:05

问题


I'm trying to share a card ( the html inside it ) from my Glassware using python and the Python Mirror API Quickstart code.

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()

I got this response back:

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

I can understand that is a permission problem but my question is, what is the suggested UI to ask to a glass user for G+ permissions?

Furthermore, by adding "https://www.googleapis.com/auth/plus.login" in the requested permissions I got this: https://www.googleapis.com/plus/v1/people/me/moments/vault?alt=json returned "Unauthorized">

Thanks in advance


回答1:


To get G+ access, you can piggyback on the authorization process that Mirror API uses. Make the following modifications to the Mirror API Python Quickstart project:

First, enable the Google+ API in the Google API Console for your project.

Second, in oauth/hander.py, add your G+ scope to the SCOPES list:

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')

Third, revoke your old auth tokens and get fresh ones. Do this by signing out of and signing back into your Quickstart instance's web front end. When you sign in, the sign in page should be updated to list the new Google+ permission:

With these steps, the code you posted should work. Comment if it doesn't and I can help you continue debugging.



来源:https://stackoverflow.com/questions/18213622/using-additional-google-apis-in-my-glassware-sharing-to-g-accounts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!