Developer's Guide: JSON-C/JavaScript (for Youtube) states that it is
possible to POST using JSON-C and JavaScript, furthermore an example
of JSON-C for creating a calendar event is shown at
http://googleappsdeveloper.blogspot.com/2010/09/new-json-format-for-google-calendar-api.html,
alas I can find no example of how this is to be implemented in
JavaScript.

I presume it cannot be done using a <script> tag since it is necessary
to set headers in the URL for Authorization, and that one should use a
POST xmlHTTPRequest Object ( or cross-browser equivalent).

I have successfully used JavaScript and YQL (to overcome cross domain
issues) to obtain the ClientLogin auth token, for use in POSTing an
event to the calendar using JavaScript and JSON-C, but no calendar
gets updated.

I would appreciate guidance as to what I am doing wrong, so here's a
code snippet used to try and post an event to the default main
calendar for my login:


var http = getHTTPObject();
var mytoken;//this becomes ClientLogin Auth token
var url="POST /calendar/feeds/default/private/full HTTP/1.1";
var params = '{"data":{"title":"Tennis with Beth","details":"Meet for
a quick lesson.","transparency":
"opaque","status":"confirmed","location":"Rolling Lawn Courts","when":
[{"start":"2011-03-17T15:00:00.000Z","end":
"2011-03-17T17:00:00.000Z"}]}}';

function getHTTPObject() {
        var http = false;
        //Use IE's ActiveX items to load the file.
        if(typeof ActiveXObject != 'undefined') {
                try {http = new ActiveXObject("Msxml2.XMLHTTP");}
                catch (e) {
                        try {http = new ActiveXObject("Microsoft.XMLHTTP");}
                        catch (E) {http = false;}
                }
        //If ActiveX is not available, use the XMLHttpRequest of Firefox/
Mozilla etc. to load the document.
        } else if (XMLHttpRequest) {
                try {http = new XMLHttpRequest();}
                catch (e) {http = false;}
        }
        return http;
}

function postMethod() {
        http.open("POST", url, true);
        //Send the proper header infomation along with the request
        http.setRequestHeader("Host", "www.google.com");
        http.setRequestHeader("Authorization", "GoogleLogin auth="+mytoken);
        http.setRequestHeader("Content-Type", "application/json");
        http.setRequestHeader("GData-Version", "2.0");
        http.setRequestHeader("Content-Length",params.length);
        http.setRequestHeader("Connection", "close");
        http.onreadystatechange = handler;
        http.send(params);
}

function handler() {//Call a function when the state changes.
        if(http.readyState == 4 && http.status == 200) {
                $("txt").value = http.responseText;
        }
}




Using Firebug I get a URL which is the my site http address appended
with /POST%20/calendar/feeds/default/private/full and a status of '301
Moved Permanently'
The Request Headers include those that I have set except for Host
which is now my site address
The Post includes JSON - 'There are no child objects'
and Source which is the params data as set for updating the event.

Any help on this would be greatly appreciated.


-- 
You received this message because you are subscribed to the Google
Groups "Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/calendar/community/forum.html

Reply via email to