遇到了这个错误,但我很困惑为什么我得到它,因为我在twitterClient.get中使用的网址是一个字符串。我已尝试查找端口并重新启动计算机,以及搜索任何语法错误都无济于事。任何帮助将不胜感激!
'use strict';
const express = require('express'),
request = require('request'),
twitter = require('twitter'),
aryMod = require('./resources/modules/objectArrayMod.js'),
app = express();
app.set('view engine', 'pug');
app.set('views', './views');
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
app.use(express.static('resources'));
app.get('/', function(req, res) {
let twitterClient = new twitter({
consumer_key: '//////',
consumer_secret: '//////',
access_token_key: '//////',
access_token_secret: '//////'
});
twitterClient.get({
url: 'https://api.twitter.com/1.1/search/tweets.json',
qs: {
q: '#csc365'
},
json: true
}, function(err, response, body) {
let tweetAry = [];
for(let i = 0; i < body.statuses.length; i++) {
let object = body.statuses[i];
let text = unescapeText(object.text);
if(text !== ''){
let repSent = text.replace(/[^a-zA-Z ]/gi, ''),
lSent = repSent.toLowerCase(),
sentenceAry = lSent.split(' '),
numOfAnagrams = 0;
for(i = 0; i < sentenceAry.length; i++){
sentenceAry[i] = sentenceAry[i].split('').sort().join();
}
for(i = 0; i < sentenceAry.length; i++){
let anagram = false;
if(sentenceAry[i] !== -1){
for(let j = i + 1; j < sentenceAry.length; j++){
if(sentenceAry[j] !== -1){
if(sentenceAry[j] === sentenceAry[i]){
numOfAnagrams++;
sentenceAry[j] = -1;
anagram = true;
}
}
}
}
if(anagram){
numOfAnagrams++;
}
sentenceAry[i] = -1;
tweetAry.push({
text: text,
anaScore: numOfAnagrams
});
}
}
}
aryMod.aryOfObjects(tweetAry);
if (!err) {
res.render('twitter', { aryMod: aryMod });
}
else {
console.error(err);
}
});
});
let unescapeText = function(escTxt) {
return escTxt.replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&');
};
const server = app.listen(3000, function () {
console.log(`Started server on port ${server.address().port}`);
});
这个服务器应该做的是动态使用包含特定主题标签的推文,计算每条推文的字谜数量,其中一个单独的AJAX文件进入并加载到页面,让你点击它们,并保持得分这些推文中的字谜数量
答案 0 :(得分:1)
查看node-twitter文档,您似乎应该使用url字符串作为第一个参数调用twitter.get(),然后然后包含您的参数的对象,如下所示:{ {1}}
以下是他们的文档中有关如何使用节点客户端搜索推文的示例:
twitterClient.get('search/tweets', params, function(err, response, body) {...})