【问题标题】:NodeJS Twitter API doesn't send tweetNodeJS Twitter API 不发送推文
【发布时间】:2015-05-16 12:56:24
【问题描述】:

我在 GitHub twit NPM 中找到并使用代码创建应用程序:

-> 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.

谁知道,我该如何解决这个问题?我也有路线文件夹。但是除了快速生成的代码之外我没有其他任何东西。

截图:http://i.imgur.com/rV0Ah8C.png

【问题讨论】:

  • app.js 的第 30 行是什么?
  • app.use(function(req, res, next) { var err = new Error('Not Found'); err.status = 404; next(err); }); 这个错误是当我去localhost:3000/update @Ryan
  • 删除或评论该行并重试。 app.use() 将在我认为你不想要的每个请求上运行该函数。
  • 除非您知道有问题,否则您不想调用 next(err)。如果没有问题,您的中间件应该调用 next();
  • @Ryan 现在打印 Cannot GET /update

标签: node.js


【解决方案1】:

好的,两个问题……

  1. 您需要将 T.get 改回 T.post。
  2. 您似乎需要更改应用程序的权限。

错误消息显示“只读应用程序无法 POST” - 您需要执行此操作才能更新状态。看看这个帖子:Why this error ' - Read-only application cannot POST '

旁注: 您在 app.js 中的代码方式意味着它将在应用程序启动时调用 twitter,并在应用程序返回时记录它。如果您将 console.log(data) 更改为 console.log(err, data) 您将能够看到错误消息。

没有理由使用您的浏览器来查看结果。你需要设置一个路由来做到这一点。

【讨论】:

    猜你喜欢
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多