Search code examples
javascriptnode.jstwittertwitter-oauth

How to fetch Twitter Username and Profile Photo using the Twit NPM Package


I am making use of the twit npm pacakge as below to get the Authenticated Twitter Username and Profile Image amongst other information.

        const Twit = require('twit');

        let T = new Twit({
            consumer_key: 'xxx',
            consumer_secret: 'xxx',
            access_token: 'xxx',
            access_token_secret: 'xxx',
            timeout_ms: 60 * 1000,  
            strictSSL: true,
        });
        T.get('users/show.json', { screen_name: `${usernameFromAbove}`}, function (err, data, response) {
            if (err) {
                console.log(`User Fetch Error`);
                console.log(err);
            }
            console.log(data);
        });

Unfortunately the response I keep getting is this:

2021-09-23T23:38:55.659299+00:00 app[web.1]:   errors: [ { message: 'Sorry, that page does not exist', code: 34 } ]

Am I calling the wrong endpoint? I'm currently confused?

Any insight to resolve this would be greatly appreciated.


Solution

  • The endpoint is 'users/show' not 'users/show.json'.