[英]Node.js issue with twitter API/bot
I'm trying to set up a twitter bot API, that creates a custom image. 我正在尝试建立一个Twitter机器人API,该API创建一个自定义图像。 When I go to run the script I get the following error: 当我运行脚本时,出现以下错误:
D:\\TwitterBot\\Node1\\bot.js:39 media_ids: [id] ^^^^^^^^^ D:\\ TwitterBot \\ Node1 \\ bot.js:39 media_ids:[id] ^^^^^^^^^^
SyntaxError: Unexpected identifier 语法错误:意外的标识符
My js file looks like this so far (redacted the API credentials for obvious reasons) 到目前为止,我的js文件看起来像这样(出于明显的原因删除了API凭据)
console.log("The bot is starting..."); var Twit = require("twit"); var T = new Twit({ consumer_key: "...", consumer_secret: "...", access_token: "...", access_token_secret: "...", }) var exec = require('child_process').exec; var fs = require('fs'); function processing() { console.log('finished'); } tweetIt(); //setInterval(tweetIt, 1000*60) //1 min function tweetIt(){ var cmd = 'processing-java --sketch=rainbow --run' exec(cmd, processing); function processing() { var filename = 'rainbow/output.png'; var params = { encoding: 'base64' } var b64 = fs.readFileSync(filename, params); T.post('media/upload', { media_data: b64 }, uploaded); function uploaded(err, data, response) { var id = data.media_id_string; var tweet = { status: '#test' media_ids: [id] } T.post('statuses/update', tweet, tweeted); } } } function tweeted(err, data, response) { if (err) { console.log('fail'); } else { console.log('pass'); } }
I'm not too sure where to start looking, everything seems to be fine in my eyes - so i'd be grateful if anyone can advise what I'm doing wrong here 我不太确定从哪里开始寻找东西,在我眼中似乎一切都很好-因此,如果有人可以建议我在这里做错了,我将不胜感激
It has nothing to do with twitter API, it's just a SyntaxError
you're missing a closing }
at the end of function tweetIt() {
它与twitter API无关,只是一个SyntaxError
您在function tweetIt() {
的末尾缺少结束function tweetIt() {
}
function tweetIt() {
function tweetIt() {
var cmd = 'processing-java --sketch="%cd%\\rainbow" --run'
exec(cmd, processing);
function processing() {
var filename = 'rainbow/output.png';
var params = {
encoding: 'base64'
}
var b64content = fs.readFileSync(filename, params);
T.post('media/upload', { media_data: b64content }, uploaded);
}
} // This was missing
Or depending what you were trying to do: 或者根据您要执行的操作:
function tweetIt() {
/* ... */
} // This was missing
function processing() {
/* ... */
}
I've now got the following error after making that change: D:\\TwitterBot\\Node1\\bot.js:39 media_ids: [id] ^^^^^^^^^ SyntaxError: Unexpected identifier I've updated the original post with the new code 进行此更改后,现在出现以下错误:D:\\ TwitterBot \\ Node1 \\ bot.js:39 media_ids:[id] ^^^^^^^^^ SyntaxError:意外的标识符我已经更新了原始帖子新的代码
You're missing a comma (,)
after status
property. 您在status
属性后缺少逗号(,)
。
function uploaded(err, data, response) {
var id = data.media_id_string;
var tweet = {
status: '#test', // Missing comma (,)
media_ids: [id]
}
T.post('statuses/update', tweet, tweeted);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.