Google calendar sync
This commit is contained in:
22
eventplanner_gcal/googleapiTest/createCredentials.py
Normal file
22
eventplanner_gcal/googleapiTest/createCredentials.py
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
from oauth2client.client import OAuth2WebServerFlow
|
||||
from oauth2client.file import Storage
|
||||
|
||||
|
||||
flow = OAuth2WebServerFlow(client_id='34462582242-4kpdvvbi27ajt4u22uitqurpve9o8ipj.apps.googleusercontent.com',
|
||||
client_secret='y4t9XBrJdCODPTO5UvtONWWn',
|
||||
scope='https://www.googleapis.com/auth/calendar',
|
||||
redirect_uri='http://localhost')
|
||||
|
||||
createLink = False
|
||||
if createLink:
|
||||
auth_uri = flow.step1_get_authorize_url()
|
||||
print "AuthURI:"
|
||||
print auth_uri
|
||||
print "Visit this link - grab the key from the url and paste it into the else block"
|
||||
exit(0)
|
||||
else:
|
||||
code = "4/Iais8aK8_KxbMQjq3Rtw3PFXu6Nr.8itpukY_6ZgZOl05ti8ZT3ax27a3hAI"
|
||||
credentials = flow.step2_exchange( code )
|
||||
storage = Storage('calendarCredentials.dat')
|
||||
storage.put( credentials )
|
||||
76
eventplanner_gcal/googleapiTest/test.py
Normal file
76
eventplanner_gcal/googleapiTest/test.py
Normal file
@@ -0,0 +1,76 @@
|
||||
from oauth2client.client import OAuth2WebServerFlow
|
||||
from apiclient.discovery import build
|
||||
from oauth2client.file import Storage
|
||||
import httplib2
|
||||
|
||||
|
||||
flow = OAuth2WebServerFlow(client_id='34462582242-4kpdvvbi27ajt4u22uitqurpve9o8ipj.apps.googleusercontent.com',
|
||||
client_secret='y4t9XBrJdCODPTO5UvtONWWn',
|
||||
scope='https://www.googleapis.com/auth/calendar',
|
||||
redirect_uri='http://localhost')
|
||||
|
||||
|
||||
#auth_uri = flow.step1_get_authorize_url()
|
||||
#print "AuthURI:"
|
||||
#print auth_uri
|
||||
#exit(0)
|
||||
|
||||
#code="4/z524dROAcIc24igDftg99LqjyJPG.4jR5ZcA_RPYaOl05ti8ZT3a5aIW3hAI"
|
||||
#credentials = flow.step2_exchange( code )
|
||||
|
||||
storage = Storage('calendarCredentials.dat')
|
||||
credentials = storage.get()
|
||||
if credentials is None or credentials.invalid == True:
|
||||
print "Invalid credentials"
|
||||
exit( 0)
|
||||
|
||||
|
||||
http = httplib2.Http()
|
||||
http = credentials.authorize( http )
|
||||
service = build( serviceName='calendar', version='v3', http=http, developerKey='blechreiz-homepage' )
|
||||
calendarId = 'blechreizensemble@gmail.com'
|
||||
|
||||
|
||||
def getEvents(pageToken=None):
|
||||
events = service.events().list(
|
||||
calendarId='primary',
|
||||
singleEvents=True,
|
||||
maxResults=1000,
|
||||
orderBy='startTime',
|
||||
timeMin='2012-11-01T00:00:00-08:00',
|
||||
timeMax='2018-11-30T00:00:00-08:00',
|
||||
pageToken=pageToken,
|
||||
).execute()
|
||||
return events
|
||||
|
||||
|
||||
def createEvent():
|
||||
print ( "Creating Event ")
|
||||
event = {
|
||||
'summary': 'Blechreiz Probe',
|
||||
'description': 'Eine Beschreibung.. bitte alle instrumente mitbringen',
|
||||
'location': 'Rohr',
|
||||
'start': {
|
||||
'dateTime': '2014-03-23T19:00:00',
|
||||
'timeZone': 'Europe/Berlin'
|
||||
},
|
||||
'end': {
|
||||
'dateTime': '2014-03-23T23:05:00',
|
||||
'timeZone': 'Europe/Berlin'
|
||||
},
|
||||
'attendees': [
|
||||
{
|
||||
'id': 'martinbauer86@gmail.com',
|
||||
'email': 'martinbauer86@gmail.com',
|
||||
'displayName': "MartinB",
|
||||
},
|
||||
],
|
||||
}
|
||||
created_event = service.events().insert(calendarId='primary', body=event).execute()
|
||||
|
||||
|
||||
print created_event['id']
|
||||
|
||||
|
||||
#createEvent()
|
||||
print getEvents()
|
||||
Reference in New Issue
Block a user