Python Google日历API创建事件返回201,但未创建任何事件

Python Google日历API创建事件返回201,但未创建任何事件,python,google-app-engine,google-api,google-calendar-api,Python,Google App Engine,Google Api,Google Calendar Api,我正在使用谷歌日历API从我的谷歌应用程序引擎应用程序中创建一个单一事件 JSON编码的事件如下所示: event = {"data":{ "title": "Test Event", "details": "Details of test event", "transparency": "opaque", "status": "confirmed", "locati

我正在使用谷歌日历API从我的谷歌应用程序引擎应用程序中创建一个单一事件

JSON编码的事件如下所示:

event = {"data":{
             "title": "Test Event",
             "details": "Details of test event",
             "transparency": "opaque",
             "status": "confirmed",
             "location": "My Place",
             "when": [{
                 "start": "2013-03-05T15:00:00.000Z",
                 "end": "2013-03-05T17:00:00.000Z"
             }]
}}
我用于添加事件的代码是:

def sendGCalEvent(self, event):
    scope = "https://www.google.com/calendar/feeds/"
    authorization_token, _ = app_identity.get_access_token(scope)
    logging.info("Using token %s to represent identity %s",
             authorization_token, app_identity.get_service_account_name())
    payload = simplejson.dumps(event)

    response = urlfetch.fetch(
        "https://www.google.com/calendar/feeds/default/private/full",
        method=urlfetch.POST,
        payload=payload,
        headers = {"Content-Type": "application/json",
                   "Authorization": "OAuth " + authorization_token})
    if response.status_code == 201:
        result = simplejson.loads(response.content)
        logging.info("Status code was %s, and the returned event looks like %s", response.status_code, result)
        return
    raise Exception("Call failed. Status code %s. Body %s",
                response.status_code, response.content)
一切似乎都正常,它验证正常,事件已发布,我得到了201响应加上事件JSON,并从日历中添加了字段

但是活动没有创建,它没有显示在我的日历上。当我转到返回的事件数据中“备用链接”字段中的URL时,我的日历会显示一条错误消息,上面写着“事件不存在”


在此方面的任何帮助都将不胜感激。我对谷歌的API非常陌生,所以希望我错过了一些明显的东西。

让它工作起来了。根据日历API的协议指南:

要发布条目,请使用一个特殊的“默认”URL(和一个授权头;请参阅上面关于身份验证的部分)向Calendar发送以下HTTP请求。Calendar自动将默认URL重定向到属于已验证用户的日历的读/写私有提要的URL。(请注意,您不必使用默认URL向日历发送POST请求;如果愿意,您可以指定用户ID而不是“默认”。有关更多信息,请参阅日历提要类型参考。)

这确实返回了201响应,但没有添加事件。但是,当我为默认用户指定用户ID时,它可以工作

POST https://www.google.com/calendar/feeds/user@website.com/private/full

我仍然不知道为什么默认提要不起作用。

从未使用过API,但您知道
200
是HTTP状态ok响应吗?我无法想象谷歌会偏离这一点。@NiklasR根据201状态代码是“请求已完成,并导致创建了一个新的资源。”在日历API的中:>当您发送第二个POST请求(或者在没有重定向的情况下发送第一个POST请求)时,日历会创建一个日历事件,然后返回一个HTTP 201创建的状态代码,以及一个元素或(JSON-C)数据对象形式的新事件副本!虽然上述方法确实有效,但它来自API的V2,我们应该使用V3。如果您想简要介绍Google Calendar API V3,请查看以下链接:
POST https://www.google.com/calendar/feeds/user@website.com/private/full