2
我很新的Twitter流媒體API和Node.js(我昨天都學到了)。我正在嘗試創建一個像https://www.youtube.com/watch?v=5b98CC9IvZ8這樣的基本程序,它可以通過twitter發送推文。我跟着亦步亦趨,但我得到這個錯誤:Twitter流API與node.js錯誤狀態代碼401在請求:<anonymous>
C:\Program Files\thesis>node twitter_collect.js
events.js:160
throw er; // Unhandled 'error' event
^
Error: Status Code: 401
at Request.<anonymous> (C:\Program
Files\thesis\node_modules\twitter\lib\twitter.js:277:28)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at Request.onRequestResponse (C:\Program
Files\thesis\node_modules\request\request.js:1074:10)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at HTTPParser.parserOnIncomingClient [as onIncoming]
(_http_client.js:473:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)
at TLSSocket.socketOnData (_http_client.js:362:20)
at emitOne (events.js:96:13)
下面是我的代碼:
var twit = require('twitter'),
twitter = new twit({
consumer_key: 'Q7IcJHDBxWtmlqSj0JgublbaJ',
consumer_secret: 'ylnM1Cfed4WMLO0VCUoIZxoLt77LTNEiqQ1h1LAtWWdfWVM2sh',
access_token: '838296902739189760-E8ZMEDA6EYLrryIOEcx2Ud5CIZiBhJQ',
access_token_secret: 'qqLAa11ysBpl4tZauPzrsITmLdJWYHr22DwGKmCkN2MI5'
});
var count = 0,
util = require('util');
twitter.stream('filter', {track: 'love'}, function(stream){
stream.on('data', function(data){
console.log(util.inspect(data));
stream.destroy();
process.exit(0);
});
});
狀態401用於未經授權的請求。你確定你的API密鑰是正確的。 PS:保持祕密 – Aditya
@Karl,你能解決這個問題嗎?我面臨同樣的問題。 – pradeep