我正在使用Google Calendar API在Google App Engine应用程序中创建单个事件事件。Google Calendar API创建事件返回201,但未创建任何事件
的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事件。
但事件没有创建,它不会显示在我的日历上。当我在返回的事件数据中的“备用链接”字段中输入网址时,我的日历中会显示一条错误消息,提示“事件不存在”
任何关于此问题的帮助都将非常感激。我对Google的API非常陌生,所以希望我错过了一些明显的东西。
从来没有使用API,但你知道'200'是HTTP状态 - 确定的响应?我无法想象谷歌会摆脱这一点。 – 2013-03-02 18:57:45
@NiklasR根据[RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)201状态代码是“请求已完成并导致创建新资源。” 从Calendar API的[procotol guide](https://developers.google.com/google-apps/calendar/v2/developers_guide_protocol#AuthOAuth): >当您发送第二个POST请求(或第一个POST请求没有重定向的情况下),Calendar创建一个日历事件,然后返回一个HTTP 201 CREATED状态代码,以及一个元素或(在JSON-C)数据对象形式的新事件的副本。 –
pointlessCog
2013-03-02 22:20:05