0
遇到此錯誤,但我很困惑,爲什麼我得到它,因爲我在我的twitterClient.get中使用的url是一個字符串。我嘗試了chaning端口並重新啓動計算機,以及搜索任何語法錯誤都無濟於事。任何幫助將不勝感激!TypeError:參數url必須是字符串,而不是對象
'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文件進來字謎量,並將其加載到頁面,讓你點擊它們,並保持這些推文上的anagrams數量的分數