{"id":12,"date":"2020-10-15T19:16:35","date_gmt":"2020-10-15T18:16:35","guid":{"rendered":"https:\/\/simonstockings.com\/?p=12"},"modified":"2020-10-22T17:23:12","modified_gmt":"2020-10-22T16:23:12","slug":"how-i-created-a-twitter-bot","status":"publish","type":"post","link":"https:\/\/simonstockings.com\/index.php\/2020\/10\/15\/how-i-created-a-twitter-bot\/","title":{"rendered":"How I Created a Twitter Bot"},"content":{"rendered":"\n<p>&#8220;Standing on the shoulders of giants&#8221; is how I created a twitter bot and it was all thanks to this code&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var Twit = require('twit')\nvar T = new Twit({\n    consumer_key:         ' ... ',\n    consumer_secret:      ' ... ',\n    access_token:         ' ... ',\n    access_token_secret:  ' ... ',\n})\nvar users = &#91;\"10228272\", \"155659213\", \"783214\"];\nvar stream = T.stream('statuses\/filter', {follow: users});\nstream.on('tweet', function (tweet) {\n    if (users.indexOf(tweet.user.id_str) > -1) {\n        console.log(tweet.user.name + \": \" + tweet.text);\n        T.post('statuses\/retweet\/:id', { id: tweet.id_str }, function (err, data, response) {\n            console.log(data)\n        })\n    }\n})\n<\/code><\/pre>\n\n\n\n<p>And this article <a href=\"https:\/\/dev.to\/oohsinan\/how-to-build-a-simple-twitter-bot-in-17-lines-ofcode-2aan\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p>I then got the twitter ID&#8217;s from <a href=\"http:\/\/gettwitterid.com\/\" data-type=\"URL\" data-id=\"http:\/\/gettwitterid.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">gettwitterid.com<\/a> and changed the above code after &#8220;Var users =&#8221;<\/p>\n\n\n\n<p>I used a command line tool called <a href=\"https:\/\/linuxize.com\/post\/how-to-use-linux-screen\/\">&#8220;Screen&#8221;<\/a> to run the twitter bot in the background on my headless Ubuntu server. It means you can come back to it at any point by using the command &#8216;screen -r&#8217;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;Standing on the shoulders of giants&#8221; is how I created a twitter bot and it was all thanks to this code&#8230; And this article here. I then got the twitter ID&#8217;s from gettwitterid.com and changed the above code after &#8220;Var users =&#8221; I used a command line tool called &#8220;Screen&#8221; to run the twitter bot [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":13,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-12","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech"],"_links":{"self":[{"href":"https:\/\/simonstockings.com\/index.php\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/simonstockings.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/simonstockings.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/simonstockings.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/simonstockings.com\/index.php\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":3,"href":"https:\/\/simonstockings.com\/index.php\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":101,"href":"https:\/\/simonstockings.com\/index.php\/wp-json\/wp\/v2\/posts\/12\/revisions\/101"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/simonstockings.com\/index.php\/wp-json\/wp\/v2\/media\/13"}],"wp:attachment":[{"href":"https:\/\/simonstockings.com\/index.php\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/simonstockings.com\/index.php\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/simonstockings.com\/index.php\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}