我的任务是使用NodeJS和Twitter API将三个Twitter个人资料推文提取到HTML的三列中。我成功地设置了服务器并提取了一个配置文件的推文,但我有点迷失了如何提取所有这三个推文,而我在任何地方都找不到答案。这是我的server.js:
var express=require('express');
var app=express();
app.set('port', process.env.PORT || 3003);
app.use(express.static(__dirname+'/public'));
app.engine('html', require('hogan-express'));
app.set('view engine', 'html');
app.get('/', function (req,res){
res.render('index', {title:'Twitter', data:theTweets});
});
app.listen(app.get('port'), function (){
console.log("listening on port: "+app.get('port'));
});
var Twitter = require('twitter');
var theTweets=[];
var config = require('./config.js');
var T = new Twitter(config);
var options = { screen_name: 'newsycombinator',
count: 30 };
T.get('statuses/user_timeline', options , function(err, data) {
if(!err){
for (var i = 0; i < data.length ; i++) {
theTweets.push(data[i].text);
}}
else {console.log(err);}
}
)
还有我的index.html:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Frontend Coding Challenge</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>{{title}}</h1>
<p>{{data}}</p>
<hr>
//<p>{{data2}}</p>
</body>
</html>
如果有人能给我提示/帮助,我将不胜感激!