gpt4 book ai didi

Node.js 获取 Twitter Streaming API - EADDRNOTAVAIL

转载 作者:太空宇宙 更新时间:2023-11-03 23:10:46 26 4
gpt4 key购买 nike

我用 node.js 编写了以下代码来访问 Twitter Streaming API。如果我 curl 下面的 URL,它就会起作用。但是,我无法让它与我的代码一起工作。

var https = require('https');

https.request('https://USERNAME:PASSWORD@stream.twitter.com/1.1/statuses/sample.json', function(res) {
res.on('data', function(chunk) {
var d = JSON.parse(chunk);
console.log(d);
});
});

但我收到以下内容

node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: connect EADDRNOTAVAIL
at errnoException (net.js:642:11)
at connect (net.js:525:18)
at Socket.connect (net.js:589:5)
at Object.<anonymous> (net.js:77:12)
at new ClientRequest (http.js:1073:25)
at Object.request (https.js:80:10)
at Object.<anonymous> (/Users/jordan/Projects/twitter-stream/app.js:3:7)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)

如果有人可以提供替代解决方案,或者向我解释为什么这不起作用,我将非常感激。

最佳答案

我最近遇到了同样的问题。这是解决方案

 var https = require('https');   
var options = {
host : 'stream.twitter.com',
path : '/1.1/statuses/filter.json?track=bob',
method : 'GET',
headers : {
"Authorization": "Basic "+new Buffer("userName:passwd").toString("base64")
}
};
var request = https.request(options,function(response){
var body = '';
response.on("data",function(chunk){
var tweet = JSON.parse(chunk);
console.log(tweet.text);
});
});
request.end();

关于Node.js 获取 Twitter Streaming API - EADDRNOTAVAIL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12333289/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com