Note that there are some explanatory texts on larger screens.

plurals
  1. POAutomatic follow back on Twitter
    primarykey
    data
    text
    <p>I now have a few thousand Twitter followers, and up until now I have been following them back manually. I now want to automate the process with PHP, as it can take ages to follow everyone back.</p> <p>I found a twitter library for PHP created by Abraham Williams and started to write some code. </p> <p>However, every time I run the script the number of users that I need to follow back is incorrect! Is this an error in my coding, or is this just how the Twitter API works?</p> <p>Here's my code:</p> <pre><code>&lt;?php require_once 'twitteroauth/twitteroauth.php'; define('CONSUMER_KEY', ''); define('CONSUMER_SECRET', ''); define('ACCESS_TOKEN', ''); define('ACCESS_TOKEN_SECRET', ''); ob_start(); set_time_limit(0); function autoFollow($action){ //auth with twitter. $toa = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); //get the last 5000 followers $followers = $toa-&gt;get('followers/ids', array('cursor' =&gt; -1)); $followerIds = array(); foreach ($followers-&gt;ids as $i =&gt; $id) { $followerIds[] = $id; } //get the last 5000 people you've followed $friends = $toa-&gt;get('friends/ids', array('cursor' =&gt; -1)); $friendIds = array(); foreach ($friends-&gt;ids as $i =&gt; $id) { $friendIds[] = $id; } if($action=="unfollow"){ //unfollow all users that aren't following back. $usersNotFollowingBackcount = 0; $usersNotFollowingBack = array(); foreach($friendIds as $id){ if(!in_array($id,$followerIds) ){ array_push($usersNotFollowingBack, $id); //unfollow the user //$toa-&gt;post('friendships/destroy', array('id' =&gt; $id)); $usersNotFollowingBackcount++; echo $usersNotFollowingBackcount.' users unfollowed so far&lt;/br&gt;'; ob_flush(); flush(); } } echo sizeof($usersNotFollowingBack).' users who weren\'t following you back have now been unfollowed!'; } if($action =="follow"){ //follow all users that you're not following back. $usersYoureNotFollowingBackcount = 0; $usersYoureNotFollowingBack = array(); foreach($followerIds as $id){ if(!in_array($id,$friendIds) ){ array_push($usersYoureNotFollowingBack, $id); //follow the user //$toa-&gt;post('friendships/create', array('id' =&gt; $id)); $usersYoureNotFollowingBackcount++; echo $usersYoureNotFollowingBackcount.' users followed back so far&lt;/br&gt;'; ob_flush(); flush(); } } echo sizeof($usersYoureNotFollowingBack).' users have been followed back!'; } } if($_GET['action']){ autoFollow($_GET['action']); ob_end_flush(); } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload