1

カレンダーが存在するかどうかを確認し、存在しない場合は作成することになっているこのコードを書きました。カレンダーを作成しようとすると、エラー 404 が返され、カレンダーが表示されません。何か案は?clientid、secret、app key を消去しました。

            import gflags
            import httplib2
            import sys, traceback

            from apiclient.discovery import build
            from oauth2client.file import Storage
            from oauth2client.client import OAuth2WebServerFlow
            from oauth2client.tools import run

            FLAGS = gflags.FLAGS

            # Set up a Flow object to be used if we need to authenticate. This
            # sample uses OAuth 2.0, and we set up the OAuth2WebServerFlow with
            # the information it needs to authenticate. Note that it is called
            # the Web Server Flow, but it can also handle the flow for native
            # applications
            # The client_id and client_secret are copied from the API Access tab on
            # the Google APIs Console
            FLOW = OAuth2WebServerFlow(
                    client_id='MY_CLIENT_ID',
                    client_secret='MY_SECRET',
                    scope='https://www.googleapis.com/auth/calendar',
                    user_agent='KUDOS_CALENDAR/v1')

            # To disable the local server feature, uncomment the following line:
            # FLAGS.auth_local_webserver = False

            # If the Credentials don't exist or are invalid, run through the native client
            # flow. The Storage object will ensure that if successful the good
            # Credentials will get written back to a file.
            storage = Storage('calendar.dat')
            credentials = storage.get()
            if credentials is None or credentials.invalid == True:
                credentials = run(FLOW, storage)

            # Create an httplib2.Http object to handle our HTTP requests and authorize it
            # with our good Credentials.
            http = httplib2.Http()
            http = credentials.authorize(http)

            # Build a service object for interacting with the API. Visit
            # the Google APIs Console
            # to get a developerKey for your own application.
            service = build(serviceName='calendar', version='v3', http=http,
                         developerKey='MY_DEV_KEY')
            kudos_calendar = None
            try:
                kudos_calendar = service.calendarList().get(calendarId='KudosCalendar').execute()
            except:
                print 'Calendar KudosCalendar does not exist!'
                print 'Creating one right now...'
                kudos_calendar_entry = {
                    'id': 'KudosCalendar'
                }

                kudos_calendar = service.calendarList().insert(body=kudos_calendar_entry).execute()
4

1 に答える 1

0

わかりました、私は回避策を見つけました。Googleの抽象化が正確に何を反映しているのかはわかりませんが、カレンダーリストを作成することはできないと確信しています。ただし、カレンダーを作成するだけであれば、すべてがうまくいき、カレンダー ID を使用して、そのカレンダーに対応するカレンダーリスト エントリにアクセスできます。

うーん.. 恐ろしく紛らわしい。また、それをしようとしているときに、ドキュメントに記載されているPythonコードの例に少なくとも2つのバグが見つかりました. 彼らはまだv3を適切に展開していないと思います.

于 2012-10-11T13:59:58.233 に答える