Итак, я начал работать над этим сценарием в Твиттере, который предназначен для пользователей, которые пишут в Твиттере о моем сайте, и я хочу настроить его с помощью cron job, чтобы поблагодарить их за это. Вот как это работает:
Парсит имена пользователей со страницы поиска (всего 15)
Перебирает все 15 имен пользователей и, если они найдены в файле twitter.txt
это остановит скрипт
Если имя пользователя не найдено в файле twitter.txt, оно напишет
имя пользователя в файл twitter.txt, а затем отправить твит этому пользователю. (файл twitter.txt помогает предотвратить отправку дубликатов твитов одному и тому же пользователю)
Так что моя проблема в том, что этот скрипт в настоящее время рассылает 15 твитов за один присест, и это будет считаться спамом. Поэтому мне нужна помощь, чтобы объединить имена пользователей в 3 твита. Таким образом, каждый твит будет содержать 5 имен пользователей. В нижней части скрипта вы увидите, где у меня есть переменные для хранения имен пользователей для твитов.
//cURL
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://search.twitter.com/search.atom?q=MYWEBSITE");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$twitter = curl_exec($curl);
curl_close($curl);
//search html source page for user names
preg_match_all('/\<uri\>http\:\/\/twitter\.com\/(.*?)\<\/uri\>/', $twitter, $usernames);
//open the twitter text file and prepare for writing
$twitter = fopen("twitter.txt", "a");
//contents of the twitter text file (holds the twitter user names)
$contents = file_get_contents("twitter.txt");
//loop through each user name
foreach($usernames[1] as $username) {
//if user name is found in the twitter text file it states "Found" and script stops
if (strpos($contents, $username) !== FALSE) {
echo $username . " - <font color=\"red\">Found</font><br />";
//if user name is not found in the twitter text file it records the user name and tweets
} else {
//write to twitter text file
fwrite($twitter, $username."\r\n");
//shows what user names were recorded
echo $username . "<br />";
//user names for tweets
//this is where i need help dividing the usernames into these variables
$usernames_set_one = "";
$usernames_set_two = "";
$usernames_set_three = "";
//tweet
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$content = $connection->get('account/verify_credentials');
//twitter message
$connection->post('statuses/update', array('status' => $usernames_set_one . ' thank you for tweeting about my website.' ));
$connection->post('statuses/update', array('status' => $usernames_set_two . ' thank you for tweeting about my website.' ));
$connection->post('statuses/update', array('status' => $usernames_set_three . ' thank you for tweeting about my website.' ));
return $connection;
}
}
//close the twitter text file no further writing
fclose($twitter);