[Javascript] javascript code to receive Oauth token from blogger using the new api

Temitope Olowookere olowott at gmail.com
Tue Aug 24 10:32:02 CDT 2010


Hi,

I am building a firefox extension that allows users to post to blogger.com,
other blogs and social websites. Please I will be very grateful  if you can
answer me and solve this code of mine. Thank you

My problem lies with receiving the Oauth token for permission or access to
be able to post on blogger.

I am new in javascript and really interested in getting better, really hurts
when you keep cracking at a code for days and no luck.

Here are the codes:

// should hold the details of the user

var args = {}; args.accountType = "HOSTED_OR_GOOGLE";
args.Email = "xyz at gmail.com";
args.Passwd = "xyz123"; args.service = "blogger";
args.source = "xyz";

        var argstring = "";

        for (var i in args) {
            argstring += encodeURIComponent(i) + "=" +
encodeURIComponent(args[i]) + "&";
        }

        argstring = argstring.substr(0, argstring.length - 1);

 // HTTP post to google server to collect Oauth token

        var req = new XMLHttpRequest();
        req.open("POST", "https://www.google.com/accounts/ClientLogin");
        req.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
        req.setRequestHeader("Content-Length", argstring.length);
        req.send(argstring);


        req.onreadystatechange = function (aEvt) {
        if (req.readyState == 4) {
                if(req.status == 200)
                    alert(req.responseText);

            else

                    alert("Error loading page\n");
                }
            }


More information about the Javascript mailing list