Coder Social home page Coder Social logo

twitter-oauth-1.1-signature-generator-js's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

twitter-oauth-1.1-signature-generator-js's Issues

Example for getting a User's tweets by user_id

Hi, thanks for the Parse implementation. Could you possibly post an example on how to get a User's tweets with the user_id param? Using the user_timeline url

I tried adding the "user_id" to the params object and changing the url, but I get an auth error (32).
I can get my own timeline fine, with out adding the user_id to the param, but not another User's.

Thanks!

Change to README.md for clarity

I believe that the Authorization link in the README.md is confusing. I'd change it to:

"Authorization": 'OAuth oauth_consumer_key="' + oauth_consumer_key + '", oauth_nonce=' + nonce + ', oauth_signature=' + encodedSig + ', oauth_signature_method="HMAC-SHA1", oauth_timestamp=' + timestamp + ',oauth_token="' + oauth_token + '", oauth_version="1.0"'

This allows copy and paste of all code, with the necessity to only change the:

  1. consumerSecret
  2. tokenSecret
  3. oauth_consumer_key
  4. oauth_token

Upload Media Endpoint never Authenticating

I'm trying to use the new https://upload.twitter.com/1.1/media/upload.json endpoint and regardless of the header variations I put in I keep getting "Request failed with response 401 , {"errors":[{"message":"Could not authenticate you","code":32}]}".

Can't produce and example of using this endpoint, I've feel like I've searched all Google has to offer and I can't find a working example. Here is what my code looks like:

var urlLink = 'https://upload.twitter.com/1.1/media/upload.json';
var consumerSecret = "XXXXXX";
var tokenSecret = "XXXXXX";
var oauth_consumer_key = "XXXXXX";
var oauth_token = "XXXXXX";
var nonce = oauth.nonce(32);
var ts = Math.floor(new Date().getTime() / 1000);
var timestamp = ts.toString();
var accessor = {
    "consumerSecret": consumerSecret,
    "tokenSecret": tokenSecret
};
var params = {
    "oauth_version": "1.0",
    "oauth_consumer_key": oauth_consumer_key,
    "oauth_token": oauth_token,
    "oauth_timestamp": timestamp,
    "oauth_nonce": nonce,
    "oauth_signature_method": "HMAC-SHA1",
    "media_data": "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAA"
};
var message = {
    "method": "POST",
    "action": urlLink,
    "parameters": params
};

//lets create signature
oauth.SignatureMethod.sign(message, accessor);
var normPar = oauth.SignatureMethod.normalizeParameters(message.parameters);
var baseString = oauth.SignatureMethod.getBaseString(message);
var sig = oauth.getParameter(message.parameters, "oauth_signature") + "=";
var encodedSig = oauth.percentEncode(sig);

Parse.Cloud.httpRequest({
    method: 'POST',
    url: urlLink,
    headers: {
        "Authorization": 'OAuth oauth_consumer_key="' + oauth_consumer_key + '", oauth_nonce="' + nonce + '", oauth_signature="' + encodedSig + '", oauth_signature_method="HMAC-SHA1", oauth_timestamp="' + timestamp + '", oauth_token="' + oauth_token + '", oauth_version="1.0"',
        'Content-Transfer-Encoding': 'base64',
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    success: function(httpResponse) {
        res.send(httpResponse.text);
    },
    error: function(httpResponse) {
        res.send('Request failed with response ' + httpResponse.status + ' , ' + httpResponse.text);
    }
});

Can't post with the sample code.

"Timeline" cloud function in the samples work without problems. I can successfully get the Twitter timeline of my user. However the status updating function gets 401 from Twitter API.
Also in the sample code you have a variable declaration "status" on this line:
var status = oauth.percentEncode(postSummary);
However, you don't use this variable anywhere or am I missing something obvious?

Twitter Get Example

Hi,

I'm trying to do a simple search call to twitter api but I get:

    {"errors":[{"message":"Could not authenticate you","code":32}]}

This is my code:

var urlLink = 'https://api.twitter.com/1.1/search/tweets.json';

var searchQuery="#mtv vine.co filter:links since:2011-11-11";
var q = oauth.percentEncode(searchQuery);
var consumerSecret = "<myConsumerSecret>";
var tokenSecret = "<myTokenSecret>";
var oauth_consumer_key = "<myConsumerKey>";
var oauth_token = "<my_token>";

var nonce = oauth.nonce(32);
var ts = Math.floor(new Date().getTime() / 1000);
var timestamp = ts.toString();

var accessor = {"consumerSecret" : consumerSecret, "tokenSecret":tokenSecret};
var message = {"method" : "GET", "action": urlLink, "parameters":oauth.decodeForm("q="+q)};
message.parameters.push(["oauth_version","1.0"]);
message.parameters.push(["oauth_consumer_key", oauth_consumer_key]);
message.parameters.push(["oauth_token", oauth_token]);
message.parameters.push(["oauth_timestamp",timestamp]);
message.parameters.push(["oauth_nonce", nonce]);
message.parameters.push(["oauth_signature_method", "HMAC-SHA1"]);

//lets create signature
oauth.SignatureMethod.sign(message, accessor);
var normPar = oauth.SignatureMethod.normalizeParameters(message.parameters);
var baseString = oauth.SignatureMethod.getBaseString(message);
var sig = oauth.getParameter(message.parameters, "oauth_signature")+"=";
var encodedSig=oauth.percentEncode(sig); //finally you got oauth signature

Parse.Cloud.httpRequest({
            method: 'GET',
            url: urlLink,
            headers: {
                "Authorization": 'OAuth oauth_consumer_key="'+oauth_consumer_key+'", oauth_nonce='+nonce+', oauth_signature='+encodedSig+', oauth_signature_method="HMAC-SHA1", oauth_timestamp='+timestamp+',oauth_token="'+oauth_token+'", oauth_version="1.0"'
            },
            success: function(httpResponse) {
                status.success(httpResponse.text);
            },
            error: function(httpResponse) {
                status.error('Request failed with response' + httpResponse.text);
            }
});

GET request for user_timeline returns 401 error

I'm trying to return a user timeline for a specific screen_name and all I'm getting back is 401 errors. The Cloud Code I'm using in my main.js:

Parse.Cloud.define("twitterTimeline", function(request, response) {
    var screen_name = "myscreenname";
    var urlLink = 'https://api.twitter.com/1.1/statuses/user_timeline.json';

    var consumerSecret = "myconsumersecret";
    var tokenSecret = "mytokensecret";
    var oauth_consumer_key = "myoauthkey";
    var oauth_token = "myoauthtoken";

    var nonce = oauth.nonce(32);
    var ts = Math.floor(new Date().getTime() / 1000);
    var timestamp = ts.toString();

    var accessor = {
        "consumerSecret": consumerSecret,
        "tokenSecret": tokenSecret
    };


    var params = {
        "oauth_version": "1.0",
        "oauth_consumer_key": oauth_consumer_key,
        "oauth_token": oauth_token,
        "oauth_timestamp": timestamp,
        "oauth_nonce": nonce,
        "oauth_signature_method": "HMAC-SHA1",
        "screen_name": screen_name,
        "count": 5,
        "include_rts": 1
    };
    var message = {
        "method": "GET",
        "action": urlLink,
        "parameters": params
    };


    //lets create signature
    oauth.SignatureMethod.sign(message, accessor);
    var normPar = oauth.SignatureMethod.normalizeParameters(message.parameters);
    console.log("Normalized Parameters: " + normPar);
    var baseString = oauth.SignatureMethod.getBaseString(message);
    console.log("BaseString: " + baseString);
    var sig = oauth.getParameter(message.parameters, "oauth_signature") + "=";
    console.log("Non-Encode Signature: " + sig);
    var encodedSig = oauth.percentEncode(sig); //finally you got oauth signature
    console.log("Encoded Signature: " + encodedSig);

    Parse.Cloud.httpRequest({
        method: 'GET',
        url: urlLink,
        headers: {
            "Authorization": 'OAuth oauth_consumer_key="'+oauth_consumer_key+'", oauth_nonce=' + nonce + ', oauth_signature=' + encodedSig + ', oauth_signature_method="HMAC-SHA1", oauth_timestamp=' + timestamp + ',oauth_token="'+oauth_token+'", oauth_version="1.0"'
        },
        body: {
        },
        success: function(httpResponse) {
            response.success(httpResponse.text);
        },
        error: function(httpResponse) {
            response.error('Request failed with response ' + httpResponse.status + ' , ' + httpResponse);
        }
    });
});

Why is this failing?

Request failed with response 401

I'm not sure if the problem is caused by the library or app settings but I'm getting this error. My keys seem to be correct. I'm trying to get home_timeline. Also Application settings access level is - Read, write, and direct messages.

Help would be appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.