簡體   English   中英

Google Calendar API創建事件返回201,但未創建任何事件

[英]Google Calendar API create event returns 201 but no event is created

我正在使用Google Calendar API從我的Google App Engine應用程序中創建一個單一事件。

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時,我的日歷出現,並顯示一條錯誤消息,提示“事件不存在”

任何幫助,將不勝感激。 我是Google API的新手,所以希望我能找到一些顯而易見的東西。

得到它的工作。 根據Calendar API的協議指南:

要發布條目,請使用特殊的“默認” URL(和授權標頭;請參閱上面的身份驗證部分),將以下HTTP請求發送到Calendar。 日歷會自動將默認URL重定向到屬於已驗證用戶的日歷的讀/寫私有提要的URL。 (請注意,您不必使用默認URL將POST請求發送到Calendar;可以根據需要指定用戶ID而不是“ default”。有關更多信息,請參閱Calendar feed類型參考。)

POST https://www.google.com/calendar/feeds/default/private/full

確實返回了201響應,但未添加事件。 但是,當我為默認用戶指定用戶ID時,它將起作用。

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

我仍然不確定為什么默認供稿不起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM