Hello friends,
Today in Developer's Blog, I am going to tell you the way to follow and unfollow someone on twitter using API.
Below is the code to follow and unfollow someone on twitter :
<?php
require("twitteroauth/twitteroauth.php");
define('CONSUMER_KEY', 'Your Consumer Key Here');
define('CONSUMER_SECRET', 'Your Consumer Secret Here');
define('ACCESS_TOKEN', 'Your Access Token Here');
define('ACCESS_TOKEN_SECRET', 'Your Access Token Secret Here');
function auto_follow()
{
$ob = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$response=$ob->post('friendships/create',array('user_id'=>'783214'));
}
function auto_unfollow()
{
$ob = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$response=$ob->post('friendships/destroy',array('user_id'=>'783214'));
}
?>
Now, you must be thinking about how to get user id of twitter account. I will tell you that also. Here's the link which will give you twitter user id by passing twitter username.
https://api.twitter.com/1/users/show.xml?screen_name=Ravinder22
You can create twitter app by going to this link :
https://dev.twitter.com/apps/new
Download Source Files
So by this way, you will successfully follow and unfollow users on twitter.
I hope this will help you and you will like it and you will follow me also on twitter.
Don't forget to leave your comments.
Thank you
Ravinder
great post 22 ji...Cheers...
ReplyDeleteFololow all who follow you and unfollow all who do not made easy with twitteroauth, read the short readme file ... https://github.com/LucasFrecia/twitter_follow_unfollow/blob/master/cursor.php
ReplyDelete