how to Get the access token using oauth.js client library?

风流意气都作罢 提交于 2020-01-23 03:45:49

问题


I'm able to get request token verifier from the library(http://oauth.googlecode.com/svn/code/javascript/), But got stuck in getting the access token.. can someone tell me where i'm doing it wrong?

 function goForAccessRequest1(verifier){

    var url2 = "http://www.google.com/accounts/OAuthGetAccessToken";

    var accessor2 = {
        token: OAuthToken,
        //tokenSecret: OAuthTokenSecret,
        signatureMethod : "HMAC-SHA1",
        consumerKey : "1010722015153-i8tisqmaqch26b0muqvefbfp3h18m862.apps.googleusercontent.com",
        //consumerSecret: "zZp8BsyfIzHJox1rBi8Lq3fm",
    };

    var message2 = {
        action: url2,
        method: "POST",
        parameters: {
            oauth_verifier : verifier,
            //scope : "http://www.google.com/calendar/feeds",
        }
    };

    OAuth.completeRequest(message2, accessor2);

    var requestBody = OAuth.formEncode(message2.parameters);

    //url2 = url2 + '?' + OAuth.formEncode(message2.parameters);

    var AccessTokenRequest = new XMLHttpRequest();
    AccessTokenRequest.open("POST", url2, true);

    AccessTokenRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    AccessTokenRequest.setRequestHeader("Authorization", "OAuth");

    AccessTokenRequest.send(requestBody);

    AccessTokenRequest.onreadystatechange = function receiveAccessToken(){
        if(AccessTokenRequest.readyState == 4){
            console.log(AccessTokenRequest.responseText)
        }
    }
}

I'm getting the error like signature error whenever i try to send the parameters using "GET", and whenevr i send the parameters in POST body, getting the error as "parameters missing"

来源:https://stackoverflow.com/questions/19239807/how-to-get-the-access-token-using-oauth-js-client-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!