1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # 4 # Copyright 2014 Google Inc. All Rights Reserved. 5 # 6 # Licensed under the Apache License, Version 2.0 (the "License"); 7 # you may not use this file except in compliance with the License. 8 # You may obtain a copy of the License at 9 # 10 # http://www.apache.org/licenses/LICENSE-2.0 11 # 12 # Unless required by applicable law or agreed to in writing, software 13 # distributed under the License is distributed on an "AS IS" BASIS, 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 # See the License for the specific language governing permissions and 16 # limitations under the License. 17 18 """Simple command-line sample for the Calendar API. 19 Command-line application that retrieves the list of the user's calendars.""" 20 21 import sys 22 23 from oauth2client import client 24 from googleapiclient import sample_tools 25 26 27 def main(argv): 28 # Authenticate and construct service. 29 service, flags = sample_tools.init( 30 argv, 'calendar', 'v3', __doc__, __file__, 31 scope='https://www.googleapis.com/auth/calendar.readonly') 32 33 try: 34 page_token = None 35 while True: 36 calendar_list = service.calendarList().list( 37 pageToken=page_token).execute() 38 for calendar_list_entry in calendar_list['items']: 39 print(calendar_list_entry['summary']) 40 page_token = calendar_list.get('nextPageToken') 41 if not page_token: 42 break 43 44 except client.AccessTokenRefreshError: 45 print('The credentials have been revoked or expired, please re-run' 46 'the application to re-authorize.') 47 48 if __name__ == '__main__': 49 main(sys.argv) 50