I am trying to implement login with twitter using the node.js ntwitter package.
https://github.com/AvianFlu/ntwitter
I am able to make API calls correctly if I hardcode my credentials, however I am can’t seem to get the Oauth request for authentication to work.
I am using Express.js. I am just trying to get an initial ‘toy’ example to work so I have just created a separate route at this point that I am visiting directly
app.get('/twitter_login', function(req, res){
var twitter = require('ntwitter');
var twit = new twitter({
consumer_key: '<Valid Consumer Key>',
consumer_secret: '<Valid Consumer Secret'});
var tlog = twit.login(req,"/login_success");
tlog(res,req,null); //Not sure on this at all
Right now the error I receive is
DEBUG: TypeError: Parameter 'url' must be a string, not undefined
at Object.urlParse [as parse] (url.js:96:11)
at handle (/usr/local/lib/node_modules/ntwitter/lib/twitter.js:341:20)
at <my app path>/app.js:47:3
I have a few questions
- The ntwitter function returns a named function called ‘handle’. Why is it named? What is the best way to call it?
- Why is login being done in 2 phases? Why not just a login function?
- Most Importantly: How do I get my users redirect to twitter so they can login?
I might be way off track here, but so feel free to suggest better methods. I would really like to stick to ntwitter though.
Thanks.
Figured this out.
2 fundamental issues
The call into ‘handle’ has the paramaters out of order
Originally I had
This should be
2.. I was rendering a template file at the end of twitter_login, which
was causing issues with redirect
======
To answer the original questions
The ntwitter function returns a named function called ‘handle’. Why is it named? What is the best way to call it?
Named likely to make it easier to see in the call stack
It can be called as such
twit.login(path.pathname,”/twitter_callback”)(req,res)
Why is login being done in 2 phases? Why not just a login function?
They are tied together, but the second call allows for a more idiomatic way to pass in the necessary information.
Most Importantly: How do I get my users redirect to twitter so they can login?
I have created a github repo that contains a working sample application.
https://github.com/drouillard/sample-ntwitter