Google App Engine And Group Provisioning
I really need some help here, I've been at this for almost 2 weeks. What I'm trying to do is use Google's provisioning API inside of GAE (Google App Engine) using oAuth2. I know th
Solution 1:
This doesn't address app engine but it is a command line example using a gdata client with oauth 2:
import sys
import os
import webbrowser
import gdata.gauth
import oauth2client.client
import oauth2client.file
import oauth2client.tools
import gdata.gauth
import gdata.client
import gdata.apps.groups.client
APICONSOLE = 'https://code.google.com/apis/console'
SCOPES = 'https://apps-apis.google.com/a/feeds/groups/'
OAUTH2FILENAME = 'credentials.oauth2'
OAUTH2JSONFILE = 'client_secrets.json'
OAUTH2USERAGENT = 'GROUPS'
MISSING_OAUTHJSONFILE_MESSAGE = """
You must create or download a client secrets json file (%s)
from the Google APIs console <https://code.google.com/apis/console>.
Attemping to open page with your browser ...
""" % os.path.join(os.path.dirname(__file__), OAUTH2JSONFILE)
# populate with approprate values
DOMAIN = 'your-domain'
GROUP_ID = 'agroup@your.domain'
if not os.path.isfile(OAUTH2JSONFILE):
message = MISSING_OAUTHJSONFILE_MESSAGE
print message
try:
webbrowser.open(str(APICONSOLE))
except Exception, e:
print "Error opening web page"
sys.exit(1)
message = 'When %s is created/downloaded press Enter to continue ... ' %(OAUTH2JSONFILE)
raw_input(message)
oauth2_flow = oauth2client.client.flow_from_clientsecrets(OAUTH2JSONFILE,
scope=SCOPES,message=MISSING_OAUTHJSONFILE_MESSAGE)
storage = oauth2client.file.Storage(OAUTH2FILENAME)
oauth2_credentials = storage.get()
if oauth2_credentials is None or oauth2_credentials.invalid:
oauth2_credentials = oauth2client.tools.run(oauth2_flow, storage)
oauth2_token = gdata.gauth.OAuth2Token(
client_id=oauth2_credentials.client_id,
client_secret=oauth2_credentials.client_secret,
scope=SCOPES,
user_agent=OAUTH2USERAGENT,
access_token=oauth2_credentials.access_token,
refresh_token=oauth2_credentials.refresh_token)
# authorize client
groups_client = oauth2_token.authorize(
gdata.apps.groups.client.GroupsProvisioningClient(domain=DOMAIN))
print 'Authorized domain %s . . .\n' %(DOMAIN)
group_entry = groups_client.RetrieveGroup(group_id=GROUP_ID)
print group_entry.group_id
print group_entry.group_name
print group_entry.description
print group_entry.email_permission
sys.exit(0)
Post a Comment for "Google App Engine And Group Provisioning"