Accessing google domain users email data with XOAUTH2

流过昼夜 提交于 2019-12-08 08:58:05

问题


I'm trying to access our students gmail data from our google apps for domains with xoauth2.

I've been around the block with this one, googles documentation is very poorly organised, and there is still alot of old docs that don't work any more that you are directed to, so it's been alot of fun.

I've basically got the following code to work using googles oauth2client in python using a service account that I created that has domain delegation enabled.

from oauth2client.client import SignedJwtAssertionCredentials

client_email = 'serviceaccount@developer.gserviceaccount.com'
with open("testserviceaccount.p12") as f:
  private_key = f.read()

credentials = SignedJwtAssertionCredentials(client_email, private_key,
    'https://www.googleapis.com/auth/gmail.readonly', sub='student email address')


from httplib2 import Http

http_auth = credentials.authorize(Http())

from apiclient.discovery import build
service = build('gmail', 'v1', http=http_auth )
messages = service.users().messages().list(userId='student email address').execute()

print messages

The app I need this to work in is in ruby on rails however, so I'm looking for any tips or help on what to use in Ruby on Rails to achieve the same effect.

Any help or tips greatly appreciated.

来源:https://stackoverflow.com/questions/30051616/accessing-google-domain-users-email-data-with-xoauth2

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