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”
thanks for your information 🙂
LikeLike
veblxob{jfc, Capsiplex review, XVkxMUM.
LikeLike
qoptzob{jfc, Prosolution pills projects showing effectiveness, cxxgRBH.
LikeLike
jmhdhob{jfc, Meratol erfahrung, IbnUlKY.
LikeLike
xsyflob{jfc, Tried semenax, NntCPvF.
LikeLike
qdvgmob{jfc/dpn, Binary option payoff, sFuhBEa.
LikeLike
pxrgcob{jfc, Joomla and web hosting, yLolZrL.
LikeLike
hzqkzob{jfc, Easy forex website, jTIphlA.
LikeLike
This design is steller! You most certainly know how
to keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost.
..HaHa!) Excellent job. I really loved what you had to say, and more than that, how you presented it.
Too cool!
LikeLike
Hey would you mind stating which blog platform you’re working with? I’m going to start my own blog in the near
future but I’m having a tough time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something completely unique.
P.S Apologies for being off-topic but I had
to ask!
LikeLike
wqkzoob{jfc, Diet dog, WFNTEiK.
LikeLike
Yes, I believe that twitter give us traffict like a bomb
LikeLike
I’m amazed, I must say. Rarely do I come across a blog that’s both educative and amusing,
and without a doubt, you’ve hit the nail on the head. The problem is an issue that too few people are speaking intelligently about. Now i’m very happy that I stumbled across this
in my search for something relating to this.
My page online marketing
LikeLike
gdxqcob{jfc, Wix 24883, XrvVgum.
LikeLike
When chоoѕing a pгoduct,
use a professional contrасtor. Moгe About Steel roοfіng auguѕtа ga
ЅhinglеsAs mentioned eaгlier, mistakeѕ can
literally cost yοu thоusаnds
of dollaгs by reroоfing аugusta ga your
homе. In countries like Germаny anԁ USA, grеen roofing auguѕta gа, and specialty ѕhingles.
When they wеге young уou
сoulԁ nevеr go wrong with synthetic, when in fact it s
just a great looκing and healthу
home. ӏt сompгises vіnyl
resins manufactured into the flеxiblе plastіс finіshed іtem.
Visit my webpage – roofing contractor
LikeLike
It’s truly a nice and useful piece of information. I am happy that you just shared this useful information with us. Please keep us up to date like this. Thanks for sharing.
my blog post; Josefina
LikeLike
ennxjob{jfc, Hcg urine, gXrPAmh.
LikeLike
ljpacob{jfc, Digital Performer 5, PrRfLFZ.
LikeLike
Greetings! I know this is kinda off topic but I was wondering which blog
platform are you using for this site? I’m getting fed up of WordPress because I’ve had problems with hackers and I’m looking at alternatives for another platform. I would be awesome if you could point me in the direction of a good platform.
LikeLike
I must thank you for the efforts you have put in writing this site.
I’m hoping to view the same high-grade content by you in the future as well. In truth, your creative writing abilities has motivated me to get my very own blog now 😉
LikeLike
I find it so inspiring that am not the only human out there over
the age of 20 who doesn’t know this kind of stuff! Time to learn *about all of it*.
LikeLike
ilsjvob{jfc, Garcinia cambogia canada, gVvIBep.
LikeLike
I have been surfing online more than 4 hours today, yet I never
found any interesting article like yours. It’s pretty worth enough for me. Personally, if all site owners and bloggers made good content as you did, the net will be much more useful than ever before.
LikeLike
blvqqob{jfc, Justhost, JWiTDoY.
LikeLike
dpbmhob{jfc, Phen375, ebQthyT.
LikeLike
Thank you kawan,, 😀
saya juga sering pakai Bot twitter, tapi bot untuk menjawab mentions otomatis,
lumayanlah membantu di twitter 😀
LikeLike
oysjpob{jfc, Lamberts pure green coffee bean extract, DekrOfh.
LikeLike
uapexob{jfc, Jes extender, ZNTlVKs.
LikeLike
bfsxhob{jfc, Optionbit Forum, kaqlguZ.
LikeLike
wfcnjob{jfc, Best hgh supplement, grCFXmQ.
LikeLike
Thank you for the auspicious writeup. It in fact was a amusement account it.
Look advanced to far added agreeable from you! By the way, how
could we communicate?
LikeLike
glxxzob{jfc, Dapoxetine priligy, tzkIgTv.
LikeLike
lcvlpob{jfc, Dapoxetine for premature ejaculation, dBwFLKb.
LikeLike
jnmxvob{jfc, Prosolution, LxhxjHf.
LikeLike
feukwob{jfc, Hersolution Review, uvqhVvh.
LikeLike
For most rесent neωs you have to go
to ѕeе web and on ωeb I found this web ѕite as a finеѕt website fοr most reсent updаtes.
Heгe is my blοg; Chong
LikeLike
cxlxaob{jfc, Renewal hgh, tStXTXg.
LikeLike
Keep on working, great job!
LikeLike
mqdatob{jfc, GenF20, WnZVoCf.
LikeLike
qjhjgob{jfc, Hgh therapy, lsLsdDq.
LikeLike
sarecob{jfc, Reverse Phone Lookup, UJAWkBL.
LikeLike
vvhhwob{jfc, Sildenafil for women, plHemnn.
LikeLike
svzqzob{jfc, Kamagra, MxRbXPB.
LikeLike
ivrhiob{jfc, Hgh vitamins, BRWbLxM.
LikeLike
xcjtqob{jfc/dpn, Sarah thompson pokies, prodHlT.
LikeLike
vvzigob{jfc, African Mango Plus Reviews, zkPvgOH.
LikeLike
iklvrob{jfc, Garcinia cambogia extract, POTmTGc.
LikeLike
zjzaoob{jfc, Triple double stars slots online, SFFaWPs.
LikeLike
vvyylob{jfc, Host Monster, afiFdkw.
LikeLike
qxlxoob{jfc, Gambling online canada, xFHrxli.
LikeLike