PHP script for auto-following Twitter users not functioning on specific account

I made a PHP program that’s supposed to auto-follow Twitter users based on certain keywords in their tweets. It’s weird because it works perfectly on several test accounts but fails on the main account I want to use.

I’ve already checked:

  • API rate limits (they’re fine)
  • Username and password (correct)

The strangest part? If I switch to another account’s credentials, it works. But when I put the main account info back in, nothing happens. I’m totally stumped!

Here’s a simplified version of what my code looks like:

// search.php
$search_url = 'https://api.example.com/search?q=KEYWORD&limit=100';
$results = json_decode(file_get_contents($search_url), true);

foreach ($results['users'] as $user) {
    $username = $user['screen_name'];
    include('auto_follow.php');
}

// auto_follow.php
$api_creds = 'myuser:mypass';
$follow_url = 'https://api.example.com/follow/' . $username;

$ch = curl_init($follow_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $api_creds);
curl_exec($ch);
curl_close($ch);

Has anyone run into something like this before? Any ideas what could be causing it?

Have you considered the possibility of account-specific API restrictions? Sometimes, Twitter imposes different limits or rules on accounts based on factors like age, activity level, or previous behavior. This could explain why your script works flawlessly on test accounts but fails on your main one.

I’d suggest reviewing your main account’s API usage history and checking for any warnings or notices from Twitter. It might also be worth temporarily increasing your logging to capture more detailed error messages or response codes from the API calls.

If all else fails, you might want to reach out to Twitter’s developer support. They can sometimes provide insights into account-specific issues that aren’t immediately apparent from our end.

I have faced a similar problem in the past, and my experience suggests it may be due to account-specific settings rather than a bug in the script itself.

It is possible that the main account is subject to additional restrictions such as privacy settings, limited API access, or even moderation rules that impact newer or less active accounts. This could explain why the code functions on test accounts but not on the main one. Checking these details and testing from different networks might provide further insight into the issue.