问题
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