简体   繁体   English

使用node.js和twitterAPI获取最新推文列表

[英]Get the list of latest tweets using node.js and twitterAPI

I got a problem to get the tweets from my account from the twitter API 1.1. 从Twitter API 1.1从我的帐户获取推文时遇到问题。 Since I am new to node.js. 由于我是node.js的新手。 I used twitter module and my intialization looks like this 我使用了twitter模块,初始化过程如下所示

twitter = require('twitter');
var twit = new twitter(params);
twit.get('http://api.twitter.com/1.1/statuses/user_timeline.json?count=2',{include_entities:false},);

But when I log the data I get this 但是当我记录数据时我得到了

[Error: HTTP Error 401: Unauthorized]statusCode: 401, data: '{"errors":[{"message":"Could not authenticate you","code":32}]}' }

Any help would be greatly appreciated. 任何帮助将不胜感激。

Error message is very clear, you need to authenticate app 错误消息很明确,您需要对应用进行身份验证

var util = require('util'),
    twitter = require('twitter');
var twit = new twitter({
    consumer_key: 'STATE YOUR NAME',
    consumer_secret: 'STATE YOUR NAME',
    access_token_key: 'STATE YOUR NAME',
    access_token_secret: 'STATE YOUR NAME'
});

https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline

https://npmjs.org/package/twitter https://npmjs.org/package/twitter

I had the same issue and found that any query parameters is supposed to be added in the second parameter on the twit.get() function. 我遇到了同样的问题,发现应该在twit.get()函数的第二个参数中添加任何查询参数。

So in your case it should be: 因此,在您的情况下应该是:

twit.get('/statuses/user_timeline.json', { count: 1 }, func);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM