0

I am working on a twitter API application and I need to use the user's access token and secret token to fetch their timeline

The twitter passport strategy gets me the tokens as follows:

passport.use(new Strategy({
consumerKey: '##################',
consumerSecret: '####################',
callbackURL: 'http://localhost:8000/twitter/callback'
}, function(token, tokenSecret, profile, callback){
    return callback(null, profile);
}));

If I console.log(token) and tokensecret inside the function, I see the token in my console however I am trying to save these tokens to a global variable to use in my other .js file. I essentially need to plug it into this :

var client = new Twitter({
consumer_key: '###########',
consumer_secret: '################',
access_token_key: 'token',
access_token_secret: 'tokenSecret'
});

Is this possible or a way to do this?

Johnson
  • 1
  • 2
  • 1
    Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – jcaron Nov 27 '17 at 07:08

1 Answers1

0

Maybe you can initialize your Twitter client into the function and assign this to a global variable in order to be used outside. If you want to use it in other modules, you need to pass it them as parameters of the functions called

David Vicente
  • 2,793
  • 1
  • 14
  • 24