This code should only unfollow users who are not following back, but it unfollows SOME followers, cannot figure out why.
$oTwitter = new TwitterOAuth (...)
$aFollowing = $oTwitter->get('friends/ids');
$aFollowing = $aFollowing->ids;
$aFollowers = $oTwitter->get('followers/ids');
$aFollowers = $aFollowers->ids;
$i=1;
foreach( $aFollowing as $iFollowing )
{
$isFollowing = in_array( $iFollowing, $aFollowers );
echo "$iFollowing: ".( $isFollowing ? 'OK' : '!!!' )."<br/>";
if( !$isFollowing )
{
$parameters = array( 'user_id' => $iFollowing );
$status = $oTwitter->post('friendships/destroy', $parameters);
} if ($i++ === 100 ) break;
}
Could it be that the problem is something else?
EDIT: Added own answer to this post with code that works to follow followers and unfollow non-followers on twitter.