from gmail.models import GmailCredentials, GmailUserInfo from yoursync import settings from oauth2client import xsrfutil from yoursync_gmail import flow_from_clientsecrets from oauth2client.django_orm import Storage from oauth2gmail import GMail_IMAP # CLIENT_SECRETS, name of a file containing the OAuth 2.0 information for this # application, including client_id and client_secret, which are found # on the API Access tab on the Google APIs # Console <http://code.google.com/apis/console> CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), '..', 'client_secrets.json') FLOW = flow_from_clientsecrets( CLIENT_SECRETS, scope='https://mail.google.com/', redirect_uri='http://vlab4.fredrikb.webfactional.com/gmail/oauth2callback', ) @login_required def index(request): storage = Storage(GmailCredentials, 'id', request.user, 'credential') credential = storage.get() if credential is None or credential.invalid == True: FLOW.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY, request.user) authorize_url = FLOW.step1_get_authorize_url() return HttpResponseRedirect(authorize_url) else:
from yoursync_gmail import flow_from_clientsecrets from yoursync_gcal import get_or_create_calendar from googlecalendar.models import GcalCredentials, GcalUserInfo # CLIENT_SECRETS, name of a file containing the OAuth 2.0 information for this # application, including client_id and client_secret, which are found # on the API Access tab on the Google APIs # Console <http://code.google.com/apis/console> CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), '..', 'client_secrets.json') FLOW = flow_from_clientsecrets( CLIENT_SECRETS, scope='https://www.googleapis.com/auth/calendar', redirect_uri='http://vlab4.fredrikb.webfactional.com/gcal/oauth2callback', ) @login_required def index(request): storage = Storage(GcalCredentials, 'id', request.user, 'credential') credential = storage.get() if credential is None or credential.invalid == True: FLOW.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY, request.user) authorize_url = FLOW.step1_get_authorize_url() return HttpResponseRedirect(authorize_url) else: