【问题标题】:Error 404 on creating a calendar with Google Calendar Api使用 Google Calendar Api 创建日历时出现错误 404
【发布时间】:2012-10-11 00:09:11
【问题描述】:

我刚刚编写了这段代码,它应该检查日历是否存在,如果不存在则创建一个。好吧,当我尝试创建日历并且日历没有出现时,它会返回错误 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()

【问题讨论】:

  • 如果没有更多详细信息(例如查看您帐户中的实际信息),这很难诊断,但我建议您查看您的日历列表。我猜发生的情况是,您第一次运行时创建了KudosCalendar,之后每次测试代码时,您都试图在已经创建的旧日历之上创建一个新日历。您可能必须删除具有该 ID 的旧日历才能创建新日历。
  • 嗨 jdotjdot,我也这么认为,但我正在查看我的日历列表,但 KudosCalendar 不存在...

标签: python google-calendar-api google-api-python-client


【解决方案1】:

好的,我找到了解决办法。我不确定谷歌抽象到底反映了什么,但我很确定不能只创建日历列表​​。但是,如果您只是创建一个日历,那么一切都会很好,然后可以使用日历 id 访问与该日历对应的 calendarlist 条目。

Ufff.. 非常混乱。同样在尝试这样做时,我在文档中给出的示例 python 代码中发现了至少两个错误。我认为他们仍然没有正确推出 v3。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-27
    • 1970-01-01
    • 1970-01-01
    • 2016-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多