node.js 创建服务器
Twitter bots have been in the news over the past few years due to election meddling, not only in the United States but stretching across the globe. There are, however, good and logical reasons for creating Twitter bots. In order to see how easy it was to create a Twitter bot, for good or evil, I decided to create my own Twitter bot. Five minutes of work and I had a working bot -- let's see how it's done!
在过去的几年中,Twitter机器人由于选举干预而备受关注,不仅在美国,而且遍及全球。 但是,创建Twitter机器人有充分而合乎逻辑的理由。 为了了解创建Twitter机器人有多么容易,无论好坏,我决定创建自己的Twitter机器人。 五分钟的工作,我有了一个正在工作的机器人-让我们看看它是如何完成的!
The first step in creating a Node.js Twitter bot is creating an app on the Twitter website:
创建Node.js Twitter机器人的第一步是在Twitter网站上创建一个应用程序 :
Provide the required information and you'll have the ability to create access token and consumer information.
提供所需的信息,您将能够创建访问令牌和消费者信息。
The next step is downloading the twit Node.js resource:
下一步是下载twit Node.js资源:
yarn install twitWith twit available, create an instance of Twit with the access token consumer information you were given by the Twitter app website:
启用twit后,使用您从Twitter应用程序网站获得的访问令牌消费者信息创建Twit实例:
const Twit = require('twit') const T = new Twit({ consumer_key: 'YOUR_INFO_HERE', consumer_secret: 'YOUR_INFO_HERE', access_token: 'YOUR_INFO_HERE', access_token_secret: 'YOUR_INFO_HERE', timeout_ms: 60 * 1000, });Now the action can happen. Here are a few examples of basic Twitter bot functionality:
现在可以采取行动了。 以下是Twitter机器人基本功能的一些示例:
// Post a tweet T.post( 'statuses/update', { status: 'This is an automated test!' }, (err, data, response) => { console.log(err, data, response); } ) // Retweet a given tweet T.post('statuses/retweet/:id', { id: '697162548957700096' })Let's think of a more practical example: using the Stream API to "like" any tweet you are mentioned in:
让我们考虑一个更实际的示例:使用Stream API来“赞”您在以下内容中提到的任何推文:
const stream = T.stream('statuses/filter', { track: ['@davidwalshblog'] }); stream.on('tweet', tweet => { console.log('tweet received! ', tweet) T.post( 'statuses/retweet/:id', { id: tweet.id }, (err, data, response) => { console.log(err, data, response); } ) } );Getting a Twitter bot up and running takes minimal effort, which is why it's important that services like Twitter protect its users from evil-doers. Bad guys aside, there are plenty of good reasons to create a Twitter bot, whether it be for internal analytics, promotion, or even creating your own Twitter app. Thank you to Tolga Tezel for creating an amazing JavaScript resources for interacting with Twitter!
启动并运行Twitter机器人只需花费很少的精力,因此,像Twitter这样的服务必须保护其用户免受恶意攻击,这一点很重要。 除了坏人,创建Twitter机器人有很多充分的理由,无论是用于内部分析,推广,还是创建自己的Twitter应用。 感谢Tolga Tezel为与Twitter交互创建了惊人JavaScript资源!
翻译自: https://davidwalsh.name/create-twitter-bot
node.js 创建服务器
相关资源:twitter-bot:Node js twitter bot为新关注者发送自动欢迎消息-源码