I have a Python Flask app that authorizes user submissions via a form by whether or not they're in a particular Google Contacts group I have (i.e. if they're not in the group, the response won't be recorded to a Google Docs Spreadsheet). Up until recently I've been using the gdata ClientLogin, and am struggling with how to get it working with the oauth2.
I've tried looking for code examples to allow permanent access to my contacts using oauth2, but haven't had much luck. The examples I've found seem to be for having users log in and then giving access to their contacts. I also haven't had much luck in finding examples of how to refresh the token. I've tried something like:
CLIENT_ID = 'GOOGLE_CLIENT_ID'
CLIENT_SECRET = 'SECRET'
SCOPE = 'https://www.google.com/m8/feeds'
USER_AGENT = 'user_agent'
auth_token = gdata.gauth.OAuth2Token(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
scope=SCOPE,
user_agent=USER_AGENT
)
APPLICATION_REDIRECT_URI = 'http://example.com'
authorize_url = auth_token.generate_authorize_url(
redirect_uri=APPLICATION_REDIRECT_URI,
access_type='offline'
)
and am able to get a code, and authorize a gdata contacts client, but not sure how to go about keeping that token alive.
Not sure if this will help but there is oauth2 parts in this that I use to bring down csv of google spreadsheets using python https://github.com/burnash/gspread