Twitter Request Token

oauth

#1
var signatureBaseString = "POST&";
    signatureBaseString += encodeURIComponent(url_baseaddress) + "&";
    signatureBaseString += encodeURIComponent("oauth_callback="+ callBack +"&");
    signatureBaseString += encodeURIComponent("oauth_consumer_key="+consumer_key+"&");
    signatureBaseString += encodeURIComponent("oauth_nonce="+oauth_nounce+"&");
    signatureBaseString += encodeURIComponent("oauth_signature_method="+signature_method+"&");
    signatureBaseString += encodeURIComponent("oauth_timestamp="+oauth_timestamp+"&");
    signatureBaseString += encodeURIComponent("oauth_version="+version+"&");

    
    console.log("Base String to be used for signing.");
    console.log(signatureBaseString);

    var secretKey = encodeURIComponent(consumer_secret_key)+"&";
    var testSignature = CryptoJS.HmacSHA1(signatureBaseString , secretKey);

    testSignature = CryptoJS.enc.Base64.stringify(testSignature);

    console.log("signature:");
    console.log(testSignature);
    
    var header_parameters = encodeURIComponent('oauth_nonce') +'="'+ encodeURIComponent(oauth_nounce) +'", ';
    header_parameters += encodeURIComponent('oauth_callback') +'="'+ encodeURIComponent(callBack) +'", ';
    header_parameters += encodeURIComponent('oauth_signature_method') +'="'+ encodeURIComponent(signature_method) +'", ';
    header_parameters += encodeURIComponent('oauth_timestamp') +'="'+ encodeURIComponent(""+oauth_timestamp) +'", ';
    header_parameters += encodeURIComponent('oauth_consumer_key') + '="'+ encodeURIComponent(consumer_key) +'", ';
    header_parameters += encodeURIComponent('oauth_signature') + '="'+ encodeURIComponent(testSignature) +'", ';
    header_parameters += encodeURIComponent('oauth_version') +'="' + encodeURIComponent(version) +'"';
    
    console.log("header parameters");
    console.log(header_parameters);
    
    //console.log(encodeURIComponent(parameters));
    fetchModule.fetch("https://api.twitter.com/oauth/request_token", {
            method: "POST",
            Authorization: "OAuth "+ header_parameters,
        })
        .then(function(response) {
            console.log("search api success");
            let webView = page.getViewById("twitterwebview");
            webView.src = response._bodyInit;
            // alert(JSON.stringify(response));
        }, function(error) {
            console.log("search api fail");
            //console.log(JSON.stringify(error));
        });

I keep getting code 215. I have tried everything in stack overflow. Can some one please help me figure out what I am missing here. I am doing this for a nativescript mobile application in javascript.


#2

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.