【问题标题】:Twitter Bot - node.js - unexpected token errorTwitter Bot - node.js - 意外的令牌错误
【发布时间】:2017-11-03 06:40:57
【问题描述】:
I'm decently new to javascript, and decided to create a twitterbot using node.js

首先我遇到了一个身份验证错误,我在文件名的末尾添加了 .js,但我没有看到任何错误消息,添加了函数和搜索,现在得到了

SyntaxError: Unexpected token }

at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:390:7)
at startup (bootstrap_node.js:150:9)

我的代码如下:

//require files

var Twit = require('twit');
var config = require('./config.js');
console.log ("THE BOT HAS STARTED!");
var T = new Twit(config);


//retweet function

var retweet = function() {
  var params = {
    q: '#perfect, #awesome' ,
    result_type: 'recent'
  }
}

Twitter.get('search/tweets', params, function(err, data) {
  // if there no errors grab id of tweet
    if (!err) {
        var retweetId = data.statuses[0].id_str;
        // Tell TWITTER to retweet
        Twitter.post('statuses/retweet/:id', {
            id: retweetId
        }, function(err, response) {
            if (response) {
                console.log('Retweeted!!!');
            }
            if (err) {
                console.log('Something went wrong while RETWEETING... 
Duplication maybe...');
        }
        });
    }
    // if unable to Search a tweet
    else {
      console.log('Something went wrong while SEARCHING...');
    }
});
}

【问题讨论】:

    标签: javascript twitter bots


    【解决方案1】:

    您需要 API Key、API Secret、Access Token 和 Access Token Secret。您将在“密钥和访问令牌”下找到。您必须通过单击“生成访问令牌”来创建访问令牌。

    【讨论】:

    • 我这样做并将其链接到一个单独的文件 (config.js)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    • 2016-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多