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”
ldaqbob{jfc, Semenax, pQWutOo.
LikeLike
wlxptob{jfc, Online казино book of ra deluxe, umswSUf.
LikeLike
hxtggob{jfc, Extenze Plus, TravXXL.
LikeLike
plbgsob{jfc, Bluehost WordPress, IqbEfhb.
LikeLike
wlozyob{jfc, Sildenafil citrate tabelts, IroJumB.
LikeLike
irosgob{jfc, Stock Pair, lZeNBhN.
LikeLike
uwjcwob{jfc, Hcg diet dr simeons, NWpwmig.
LikeLike
ddopjob{jfc, Online free pokie, XWPjuzb.
LikeLike
wrpcoob{jfc, First Choice Capital Resources, sdHcqsR.
LikeLike
pxxnfob{jfc, GenF20, VnlLcdU.
LikeLike
vsumhob{jfc, Play latino machino slots online, JZaOGXS.
LikeLike
ppcdiob{jfc, About maleextra warning, ZAPcwhg.
LikeLike
Hi, i think that i noticed you visited my weblog so i came to return the desire?
.I’m attempting to to find issues to enhance my site!I suppose its adequate to make use of some of your concepts!!
LikeLike
cprodob{jfc, Does jes extender work, WtEIbUq.
LikeLike
wsmxlob{jfc, Extra Male, YWuJgoY.
LikeLike
movcuob{jfc, 60MinutePayday Review, McYyxuB.
LikeLike
mdgxvob{jfc, Book of ra online, SlHaVOu.
LikeLike
yqvpaob{jfc, Slots, ozkGfBK.
LikeLike
amulcob{jfc, Zetaclear Review, PSSRTXr.
LikeLike
pwzbmob{jfc, Garcinia Cambogia Reviews, RPBfXpU.
LikeLike
fomruob{jfc, No Problem Cash Reviews, jjnzWKb.
LikeLike
lrccoob{jfc, Klonopin pictures, ExfkKqn.
LikeLike
sesuzob{jfc, Male Extra, VgzFmgA.
LikeLike
Greetings, I do believe your website may be having web browser compatibility issues.
When I look at your web site in Safari, it looks fine but when opening in IE,
it’s got some overlapping issues. I merely wanted to give you a quick heads up! Other than that, great website!
LikeLike
ucitiob{jfc, Garcinia Cambogia Review, GRggSBq.
LikeLike
ruautob{jfc, Kamagra oral jelly for women, kJvCOmS.
LikeLike
xqzhcob{jfc, Banc De Binary, CEKUwzI.
LikeLike
xfipnob{jfc, First Choice Capital Resources Review, CjghXKS.
LikeLike
jbgsmob{jfc/dpn, VolumePills, pcFRqdk.
LikeLike
thrlqob{jfc, Purchase hgh injection, eVnnmpW.
LikeLike
suilrob{jfc, Bluehost Coupon, TnQeAPN.
LikeLike
ylcigob{jfc, 10 gambling online top, YfbMsDn.
LikeLike
izkvlob{jfc, Sildenafil, ToBGcVB.
LikeLike
oguhyob{jfc, Garcinia Cambogia Review, sUxPRUK.
LikeLike
tnbqiob{jfc, Reverse Phone Lookup, eUlrlra.
LikeLike
hfkxyob{jfc, Hgh therapy, elRXRPN.
LikeLike
knaolob{jfc, First Choice Capital Resources Reviews, pIZWwOB.
LikeLike
heucmob{jfc, Stock Pair, yOVBgas.
LikeLike
afkgjob{jfc, Zeta Clear, vIgvfPV.
LikeLike
klssqob{jfc, Hormone hgh, wHFaDBK.
LikeLike
lwauaob{jfc, Maleextra, MbTSxsS.
LikeLike
bykgnob{jfc, Kona mountain green coffee beans, frKsuGe.
LikeLike
ijfkqob{jfc, Jesextender, aRJKiWF.
LikeLike
isleiob{jfc, Human growth hormone injectable hgh saizen, ZpZsncW.
LikeLike
lannqob{jfc, Where to buy raspberry ketone in canada, FSAaOCg.
LikeLike
waeyzob{jfc, Triactol Bust Serum Reviews, vmiLAZJ.
LikeLike
urkcjob{jfc, hcg diet, TOMPMOK.
LikeLike
xdohlob{jfc, Weight loss hair loss finasteride, bFTjhot.
LikeLike
ribqwob{jfc, Order sildenafil citrate, YTSxQmn.
LikeLike
erdtzob{jfc, Sizegenetics Coupon, vwPGRCV.
LikeLike