Closed GoogleCodeExporter closed 8 years ago
The code for getting all the items should be:
service = build("calendar", "v3", http=http)
events = service.events()
request = events.list(calendarId='primary')
while (request != None):
response = request.execute(http)
for e in response['items']:
print e.get('summary', '')
request = events.list_next(request, response)
Original comment by jcgregorio@google.com
on 7 Feb 2012 at 5:13
Will mark as Fixed for now. Re-open if you are still having problems.
Original comment by jcgregorio@google.com
on 7 Feb 2012 at 7:35
Still having the problem. Here is the exception error message :
******************************
Traceback (most recent call last):
File "GoogleCal.py", line 326, in <module>
main()
File "GoogleCal.py", line 304, in main
for e in response['items']:
KeyError: 'items'
I used your code, and replace 'primary' by a secondary calendar ID (and i'm
pretty sure of the ID, got in Gcal settings).
And I can't explain the error, the secondary cal is full of items...
Original comment by pschi...@gmail.com
on 7 Feb 2012 at 8:17
Use the calendarList().list() to get the list of calendars and their associated
ids:
http://api-python-client-doc.appspot.com/calendar/v3/calendarList
Original comment by jcgregorio@google.com
on 7 Feb 2012 at 8:27
That's what I do.
Here is my code :
#getting all calendars
calendar_list = service.calendarList().list().execute()
#getting the right calendar ID from calendarName
while True:
for calendar_list_entry in calendar_list['items']:
summary = calendar_list_entry['summary']
id = calendar_list_entry['id']
if summary == calendarName:
idCalendar = id
break
page_token = calendar_list.get('nextPageToken')
if not page_token:
break
# Getting all events from this calendar ID
events = service.events()
request = events.list(calendarId=idCalendar)
while (request != None):
response = request.execute(http)
for e in response['items']:
print e.get('summary', '')
request = events.list_next(request, response)
And same old error...
Original comment by pschi...@gmail.com
on 8 Feb 2012 at 10:47
Here is a quick and dirty sample that I wrote that lists 3 items from every
calendar in my calendar list.
http://codereview.appspot.com/5642058/
Note that there is a check for no 'items' in the response, which will happen if
you don't have permissions to list the events in a calendar. That actually
happens for me when it gets to the Google Doodles calendar:
{'accessRole': 'reader',
'description': '',
'etag': '"0fiVPdkp7hkeMUTcCsWdW66wVVc/M0i94UPrRxmG73b08eohQVflQis"',
'kind': 'calendar#events',
'summary': 'Google Doodles',
'timeZone': 'America/New_York',
'updated': '2012-02-08T11:51:44.000Z'}
Original comment by jcgregorio@google.com
on 8 Feb 2012 at 2:33
Here what i get with your script :
{u'accessRole': u'owner',
u'etag': u'"XXXXX"',
u'kind': u'calendar#events',
u'nextPageToken': u'XXXXX',
u'summary': u'TEST',
u'timeZone': u'Europe/Paris',
u'updated': u'2012-02-07T20:06:41.000Z'}
No items listed while it's full of items (over 30...)
BTW I can add items as many as I want to this calendar
Weird...
Original comment by pschi...@gmail.com
on 8 Feb 2012 at 8:04
So this looks like the Python client is working fine and may be an issue with
permissions in Calendar. You can ask about that on the Calendar API forum:
http://code.google.com/apis/calendar/community/forum.html
Original comment by jcgregorio@google.com
on 9 Feb 2012 at 1:40
Thanks.
Too bad that they don't seem very reactive on the API forum.
Original comment by pschi...@gmail.com
on 9 Feb 2012 at 2:31
I am getting the same error - KeyError
I did find that start and end, which are dictionaries work, but the unicode
string generates the error consistently.
Start = {u'dateTime': u'2010-11-11T12:16:24-08:00'}
End = {u'dateTime': u'2010-11-11T13:16:24-08:00'}
Text = New title for single event
Start = {u'dateTime': u'2010-11-11T12:16:28-08:00'}
End = {u'dateTime': u'2010-11-11T12:16:28-08:00'}
Traceback (most recent call last):
File "sample.py", line 153, in <module>
main(sys.argv)
File "sample.py", line 130, in main
myText = event[u'summary']
KeyError: u'summary'
$ python
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
CODE:
interval = 0
txt = ""
while True:
events = service.events().list(calendarId='primary', pageToken=page_token).execute()
for event in events['items']:
if interval < 5:
#dt = dateutil.parser.parse(event['start']['date'])
print 'Start = ',event[u'start']
print ' End = ', event[u'end']
myText = event[u'summary']
print 'Text = ',myText
page_token = events.get('nextPageToken')
interval += 1
else:
break
if not page_token:
break
Original comment by mark.eckdahl
on 26 Jun 2014 at 6:59
Found work around using get function:
myText = event.get(u'summary') # WORKS
print 'Text = ',myText
Original comment by mark.eckdahl
on 26 Jun 2014 at 7:17
Original issue reported on code.google.com by
pschi...@gmail.com
on 5 Feb 2012 at 7:56