0

I found in GitHub twit NPM and create app with the code:

-> express twitter
-> in the app.js:


var T = new Twit({
consumer_key:         'AAA',
consumer_secret:      'BBB',
access_token:         'CCC',
access_token_secret:  'DDD'
})

T.post('/update', { status: 'hello world!' }, function(err, data, response) {
 console.log(data)
}) 
// I write it in the end of whole code that generated by express. But when I start 
it with the comand node app.js it prints "undefined" and 404 Not Found when 
I run it from browser.

Who knows, how can I solve this problem? I also have routes folder too. But anything else in addition of express generated code I do not have.

Screenshot: https://i.stack.imgur.com/JQZbP.png

  • What is on line 30 of app.js? – Ryan Mar 13 '15 at 21:58
  • `app.use(function(req, res, next) { var err = new Error('Not Found'); err.status = 404; next(err); });` this error is when i go to `localhost:3000/update` @Ryan – Orkhan Alizade Mar 13 '15 at 22:02
  • Remove or comment that line out and try again. app.use() will run that function on every request which I don't think you want. – Ryan Mar 13 '15 at 22:12
  • You don't want to call next(err) unless you know that there is a problem. If there is not a problem your middleware should just call next(); – Ryan Mar 13 '15 at 22:20
  • @Ryan now it prints `Cannot GET /update` – Orkhan Alizade Mar 13 '15 at 22:23
  • It may be easier if I could see your whole app.js. From the code you posted I don't see anything along the lines of app.get('/update', ....); – Ryan Mar 13 '15 at 22:25
  • @Ryan I run at first in the terminal `express twitter`. Add to the dependencies + twit and run npm install. Later I just changed app.js => http://pastebin.com/x4xv7rvt – Orkhan Alizade Mar 13 '15 at 22:29

1 Answers1

0

Okay two issues...

  1. You need to change T.get back to T.post.
  2. It looks like you need to change permissions on your Application.

The error message says "Read only-application cannot POST" - which you need to do to be able to update the status. Take a look at this post: Why this error ' - Read-only application cannot POST '

Side note: The way you have your code in app.js means that it will make the call to twitter when the app starts and log it when it comes back. If you change your console.log(data) to console.log(err, data) you will be able to see the error messages.

There is no reason to use your browser to see the results. You would need to set up a route to do that.

Community
  • 1
  • 1
Ryan
  • 5,845
  • 32
  • 27