Twitter has announced to shut down the Basic Authentication API on August 31st and recommend Twitter application developers to migrate their apps to OAuth Authentication. What about bots? That’s the same. If you have bot created using Basic Authentication, then you should migrate your bot to OAuth. Here’s how, but first..
What is OAuth?
OAuth is a new authentication method that doesn’t use plain username & password to authenticate. OAuth uses a pair of tokens to check your credentials, therefore you don’t need to worry about leaking your password. These tokens are unique per user and per application. For further info about OAuth, check http://oauth.net/
So how?
First thing you need to do after creating bot account is creating an application. Go to http://dev.twitter.com/apps/new with your bot account and fill the form.
– Name: the application name will be shown after “via” in your tweets
– Application Type: You must choose ‘Browser’
– Default Access Type: Choose ‘Read and Write’
– Everything else you can fill any value
After created, go to you application detail. There you can see ‘Consumer Key’ and ‘Consumer Secret’ value. Save these keys.
Then click ‘My Access Token’ button in the right. You will see your ‘Access Token’ and ‘Access Token Secret’. You should save these keys too.
And now let’s go to the code!
You’ll need some libraries to utilize OAuth functions, so download Abraham’s TwitterOAuth library first. Copy the OAuth.php & twitteroauth.php files from downloaded library to your server, and create a new PHP file in the same directory.
And here’s the code:
this is the code I use for my bot @juru_doa 😉
require_once('twitteroauth.php'); define('CONSUMER_KEY', 'insert_your_consumer_key_here'); define('CONSUMER_SECRET', 'insert_your_consumer_secret_here'); define('ACCESS_TOKEN', 'insert_your_access_token_here'); define('ACCESS_TOKEN_SECRET', 'insert_your_access_token_secret_here'); $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); $twitter->host = "http://search.twitter.com/"; $search = $twitter->get('search', array('q' => 'semoga', 'rpp' => 20)); $twitter->host = "https://api.twitter.com/1/"; foreach($search->results as $tweet) { $status = 'Amiiiin RT @'.$tweet->from_user.' '.$tweet->text; if(strlen($status) > 140) $status = substr($status, 0, 139); $twitter->post('statuses/update', array('status' => $status)); }
What above code does?
After authenticating the OAuth tokens, it will do a search for ‘semoga’ keyword and grab the 20 most recent tweets. You can set another keyword for your bot. Then it will ReTweet each tweets and and ‘Amiiin’ before it.
To try whether you bot works or not, you can access your script from a browser. If the displays blank page, then your script might be work. Go check the timeline to make sure.
The last step is creating a cron job to run your script in certain times. How? That part is what you should do yourself 😆
Tips: Don’t run your bot too often, like in every minutes, and don’t tweet too much, since there are limitation from Twitter.
Discuss about Twitter Bot here
190 replies on “How to Create Twitter Bot using OAuth”
xxvegob{jfc, Binary options best broker review compare, xPcPwmp.
LikeLike
ahulpob{jfc, Teeth whitening pro, WkopVYG.
LikeLike
uiqgeob{jfc, Kostenlos spielen 1001, ASOHMpM.
LikeLike
vphocob{jfc, Slots Online, tFkEENF.
LikeLike
plhrkob{jfc, Extenze, WfQRKio.
LikeLike
fnbvkob{jfc, Vardenafil precautions, yjVTpJg.
LikeLike
hmcccob{jfc, Hostmonster, NrpoEeJ.
LikeLike
meidkob{jfc, Priligy, BVmLydQ.
LikeLike
qwkctob{jfc, Stock Pair, DkByDxY.
LikeLike
glnjpob{jfc, Buy priligy online, SApPtEG.
LikeLike
zeyavob{jfc, Hgh tablets, stEbhMi.
LikeLike
Thanks a bunch for sharing this with all people you really realize what you are
talking approximately! Bookmarked. Please also discuss with my
website =). We can have a hyperlink change agreement between us
LikeLike
vgkhlob{jfc, Web2Cars Review, hfRHcZM.
LikeLike
Hi there, neat webpage you’ve gotten going here.
LikeLike
If you would like to take a good deal from this post then you have to apply such strategies to your won blog.
LikeLike
nice gan.
LikeLike
kunjungan rutin 🙂
LikeLike
I want to to thank you for this good read!! I certainly enjoyed
every bit of it. I have got you saved as a favorite to
look at new things you post…
LikeLike
whoah this blog is wonderful i like studying your articles.
Stay up the good work! You understand, lots of people are looking around for this info, you
can aid them greatly.
LikeLike
Thanks for finally talking about > How to Create Twitter
Bot using OAuth | Theater of Dreams < Loved it!
LikeLike
Hello there good weblog! Man. Fantastic. Astounding. I’ll take note of your blog and consider the rss feeds as well? I am just grateful to seek out lots of very helpful details in this create, we require figure out more methods within this consideration, thank you for giving.
LikeLike
Admiring the time and energy you put into your
site and detailed information you offer. It’s good to come across a blog every once in a while that isn’t the same out of date rehashed material.
Fantastic read! I’ve saved your site and I’m adding
your RSS feeds to my Google account.
LikeLike
I have an Twitter account for almost 3 years 😀
PTC Membayar
LikeLike
Thank you for the post. As we know, we can use twitter for marketing.
Actually, I just know this trick. Thanks for information.
LikeLike
baju batik couplenice info gan, ane tunggu artikel yang lain
LikeLike
izin nyimak artikelnya sob, kayanya pada menarik artikelnya ini.
LikeLike
apa tidak riskan tuh gan, btw keep posting. terus berkarya
LikeLike
upps.. doeble post. tengkyu info artikelnya gan
LikeLike
Sedang nyari bot buat twitter nemu artikel ini, perlu dicoba dulu nih sebelum bisa komentar. Terima kasih ya gan…
LikeLike
bahasa indonesianya gan???
LikeLike
Nice….info
Thanks for sharing
tips cara agar artikel cepat terindeks google
penyebab artikel sulit di indeks google
LikeLike
pempek candy
LikeLike
i dont know what u say, your blog is gado-gado.. hehehehe.. salam..
LikeLike
Great post. I was checking constantly this blog and I am impressed!
Extremely useful info specially the remaining section 🙂
I take care of such info much. I used to be looking for this certain info for a long time.
Thank you and good luck.
LikeLike
kaga ngerti o.O
LikeLike
Hi , saya percaya yang saya saw Anda mengunjungi
saya situs sehingga i datang untuk kembali yang memilih
saya ?. mencoba menemukan isu untuk meningkatkan saya situs web kurasa!
fiturnya cukup baik memanfaatkan beberapa dari Anda ide !!
LikeLike
First off I want to say fantastic blog! I had a quick question which
I’d like to ask if you do not mind. I was curious to find out how you center yourself and clear your
thoughts prior to writing. I’ve had a hard time clearing my thoughts in getting my thoughts out.
I truly do enjoy writing however it just seems like the first 10 to 15 minutes tend to be wasted simply just
trying to figure out how to begin. Any suggestions or tips?
Kudos!
LikeLike