HTTPClient - Google Calendar - request body
Hi,
(Android, API 1.4, TD 1.2.1)
I'm trying to create an event in the Google calendar with HTTPClient. I got through with authentication, I got a list of calendars, but when trying to create an event, I get a wrong response. I get a HTTP status 200 (OK), when I should get 201 (CREATED).
I think I don't get the body part of the request right.
In the API docs of Google Calendar (http://code.google.com/intl/sl-SI/apis/calendar/data/2.0/developers_guide_protocol.html#CreatingEvents) it says one should send an Event, e.g.
{
"data": {
"title": "Tennis with Beth",
"details": "Meet for a quick lesson.",
"transparency": "opaque",
"status": "confirmed",
"location": "Rolling Lawn Courts",
"when": [
{
"start": "2010-04-17T15:00:00.000Z",
"end": "2010-04-17T17:00:00.000Z"
}
]
}
}
I tried it in some ways, but it all returns the same result.
My code:
var oc = Ti.Network.createHTTPClient();
oc.open('POST', 'https://www.google.com/calendar/feeds/default/private/full/?alt=jsonc');
oc.setRequestHeader("Authorization", "GoogleLogin auth=" + token);
oc.setRequestHeader("GData-Version", 2);
oc.setRequestHeader("Content-Type", "application/json; charset=utf-8");
oc.send({body: data});
On the last line, the data variable is the json-c code above.
The response I get is:
{
"apiVersion":"2.3",
"data":
{"kind":"calendar#eventFeed","id":"http://www.google.com/calendar/feeds/my_email/private/full","author":{"displayName":"Ultich II.","email":"my_email"},"title":"calendar_title","details":"cal_title","updated":"2010-11-04T10:21:25.000Z","totalResults":0,"startIndex":1,"itemsPerPage":25,"feedLink":"https://www.google.com/calendar/feeds/my_email/private/full","selfLink":"https://www.google.com/calendar/feeds/my_email/private/full?alt\u003djsonc&max-results\u003d25","canPost":true,"timeZone":"Europe/Belgrade","timesCleaned":1}
}
I tried different combinations for sending body in the
oc.send({body: data});
line, but all of them return the same response, so I guess it's this line thats wrong.
Thank you for reading this, hope someone shed some light on this.
4 Answers
-
Hi,
I try to connect to google calendars, How did you do this ? I got my token, but whien I do
var xhr=Ti.Network.createHTTPClient(); xhr.onload=function() { Ti.API.error("XHR OnLoad :"+this.responseText); }; xhr.onerror=function() { Ti.API.error("XHR OnError :"+this.status+" : "+this.responseText); }; xhr.open("GET",'https://www.google.com/calendar/feeds/default/private/full/?alt=jsonc'); xhr.setRequestHeader("Authorization"," GoogleLogin auth="+MyAuth); xhr.send();
I allways fall in onerror, can you help me please
-
I didn't solve it.
Now I'm making requests to my PHP server, then using CURL to get the data I want and return it to the device.. -
"I allways fall in onerror"
What does the "responseText" tell you ?
-
Matej Franca
How did you get the list of calendars? I am done with the authentication part but unable to fetch any data from google calendar.I used the same code as Aurelien GIRARD pasted here. any helpThanks