I have this PHP script that I wrote to automatically follow users that post messages with certain terms. It works 100% of the time on a bunch of test accounts but then does not work on the account I'd like to use it with.
I've checked the account's API rate limit and it's well within the boundaries. I've also verified that the username and password are correct. If I change nothing else but the username and password to another account it will work, but when changed back (correctly) to the main account nothing happens. I am totally baffled. Has anyone ever come across this?
I'm including the two files used below. If there's any other info that would be helpful, let me know and I'll provide it if I can. Thanks!
Index.php
<?php
$url = "http://search.twitter.com/search.atom?q=SEARCHTERM&show_user=true&rpp=100";
$search = file_get_contents($url);
$regex_name = '/\<name\>(.+?) \(/';
preg_match_all($regex_name,$search,$user);
for($i=0;$user[1][$i];$i++)
{
$follow = $user[1][$i];
include("follow.php");
}
?>
Follow.php
<?php
define('TWITTER_CREDENTIALS', 'username:password');
$url = "http://twitter.com/friendships/create/".$follow.".xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, TWITTER_CREDENTIALS);
$result= curl_exec ($ch);
curl_close ($ch);
?>
Quick update on this: Turns out the problem was on Twitter's end--the account in question had tighter than normal API limits imposed for some reason. I'm not marking any responses as the answer since it was a rather idiosyncratic instance.