Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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.

— asked November 4th 2010 by Matej Franca
  • body
  • calendar
  • google
  • httpclient
  • mobile
  • send
0 Comments

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

    — answered February 9th 2011 by Aurelien GIRARD
    permalink
    0 Comments
  • 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..

    — answered February 9th 2011 by Matej Franca
    permalink
    0 Comments
  • "I allways fall in onerror"

    What does the "responseText" tell you ?

    — answered February 9th 2011 by Stephen Gilboy
    permalink
    0 Comments
  • 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 help

    Thanks

    — answered March 20th 2014 by Sanjay Gohil
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.