1
votes

I am using twitter api using Auth 1.0 and it is working well when using url = 'https://api.twitter.com/1.1/statuses/home_timeline.json' but when I am using https://api.twitter.com/1.1/search/tweets.json?q=nasa&result_type=popular api its returning

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

}

Now I am not understanding why it is happening... Following is the header I am making:

function buildRequestHeader(httpMethod, URL) {
    parameters = {
        oauth_consumer_key: CONSUMER_KEY,
        oauth_token: ACCESS_TOKEN,
        oauth_nonce: getNonce(),
        oauth_timestamp: getTimestamp(),
        oauth_signature_method: 'HMAC-SHA1',
        oauth_version: '1.0',
    },

    signature = oauthSignature.generate(httpMethod, URL, parameters, CONSUMER_SECRET, ACCESS_TOKEN_SECRET,{ encodeSignature: false }),

    authString = 'OAuth oauth_consumer_key=' + parameters.oauth_consumer_key + ',oauth_token=' + parameters.oauth_token + ',oauth_signature_method=HMAC-SHA1,oauth_timestamp=' + parameters.oauth_timestamp + ',oauth_nonce=' + parameters.oauth_nonce + ',oauth_version=1.0,oauth_signature=' + encodeURIComponent(signature);
    return authString;
    console.log('>>>>>>>', authString);
}

It is returning me header for twitter which is working well for url = 'https://api.twitter.com/1.1/statuses/home_timeline.json' but error code 32 for https://api.twitter.com/1.1/search/tweets.json?q=nasa&result_type=popular api.Thank you .Any help will be appr

2
Any updates with the code? I have got the same problem.Sanchit Bhatnagar

2 Answers

0
votes

It's been a while, but I believe that your oath parameters need to appear in the AuthString in alphabetical order by parameter name.

0
votes

Please check your Twitter Application. Twitter Application. In App details, 'Sign in with Twitter' must be 'enabled'.