Use 2 legged in Google API v3 for python -


i have code describe here. need create lot of events in calendar.

i cannot find way make work. using 2 legged seems deprecated

import sys import httplib2  rfc3339 import rfc3339 apiclient.discovery import build oauth2client.file import storage oauth2client.client import accesstokenrefresherror oauth2client.client import flow_from_clientsecrets oauth2client.tools import run import pytz import datetime import time start_zone = pytz.timezone('europe/london') end_zone = pytz.timezone('europe/oslo')  start_time = datetime.datetime(2013,8,13,15,0, tzinfo=start_zone) end_time = datetime.datetime(2013,8,16,19,0, tzinfo=end_zone)   flow = flow_from_clientsecrets('client_secrets.json',     scope='https://www.googleapis.com/auth/calendar',     redirect_uri='http://localhost')  storage = storage('credentials.dat') credentials = storage.get() if credentials none or credentials.invalid:   credentials = run(flow, storage)  http = httplib2.http() http = credentials.authorize(http) service = build('calendar', 'v3', http=http)  try:    event = {     'start': {       'datetime': start_time       },     'end': {       'datetime': end_time       },     "summary": "new event",     "location": "paris, france"   }   service.events().insert(calendarid='primary', body=event).execute()   print "end" except accesstokenrefresherror:   print ('credentials have been revoked') 

i have updated code way (since don't have redirection)

#!/usr/bin/python import sys import httplib2  rfc3339 import rfc3339 apiclient.discovery import build oauth2client.file import storage oauth2client.client import accesstokenrefresherror oauth2client.client import flow_from_clientsecrets oauth2client.tools import run import pytz import datetime import time start_zone = pytz.timezone('europe/london') end_zone = pytz.timezone('europe/oslo')  start_time = datetime.datetime(2013,8,13,15,0, tzinfo=start_zone) end_time = datetime.datetime(2013,8,16,19,0, tzinfo=end_zone)  flow = flow_from_clientsecrets('client_secrets.json',     scope='https://www.googleapis.com/auth/calendar',     redirect_uri='urn:ietf:wg:oauth:2.0:oob')  auth_uri = flow.step1_get_authorize_url() print('visit site!') print(auth_uri) code = raw_input('insert given code!') credentials = flow.step2_exchange(code) print(credentials)  open('credentials.dat', 'wr') f:   f.write(credentials.to_json())  storage = storage('credentials.dat') credentials = storage.get() if credentials none or credentials.invalid:   credentials = run(flow, storage)  http = httplib2.http() http = credentials.authorize(http) service = build('calendar', 'v3', http=http)  try:   event = {     'start': {       'datetime': start_time       },     'end': {       'datetime': end_time       },     "summary": "new event",     "location": "paris, france"   }   service.events().insert(calendarid='primary', body=event).execute()   print "end" except accesstokenrefresherror:   print ('credentials have been revoked') 

so when run script, opens window ad asking me login. put gmail username/password , have following error after that:

error: redirect_uri_mismatch redirect uri in request: urn:ietf:wg:oauth:2.0:oob did not match registered redirect uri  

the error message indicates client_secrets.json used not installed application. try recreating client id in api console , making sure specify it's installed application.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -