我現在有幾千個Twitter追隨者,並且到現在爲止我已經回到手工跟了上去。我現在想用PHP自動化這個過程,因爲它可能需要很長時間才能追隨每個人。自動跟蹤回在Twitter上
我發現亞伯拉罕·威廉姆斯創建的PHP嘰嘰喳喳庫,並開始編寫一些代碼。
但是,每次我運行該腳本,我需要遵循回來的用戶數時間不正確!這是我編碼中的錯誤,還是Twitter API的工作原理?
這裏是我的代碼:
<?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->get('followers/ids', array('cursor' => -1));
$followerIds = array();
foreach ($followers->ids as $i => $id) {
$followerIds[] = $id;
}
//get the last 5000 people you've followed
$friends = $toa->get('friends/ids', array('cursor' => -1));
$friendIds = array();
foreach ($friends->ids as $i => $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->post('friendships/destroy', array('id' => $id));
$usersNotFollowingBackcount++;
echo $usersNotFollowingBackcount.' users unfollowed so far</br>';
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->post('friendships/create', array('id' => $id));
$usersYoureNotFollowingBackcount++;
echo $usersYoureNotFollowingBackcount.' users followed back so far</br>';
ob_flush();
flush();
}
}
echo sizeof($usersYoureNotFollowingBack).' users have been followed back!';
}
}
if($_GET['action']){
autoFollow($_GET['action']);
ob_end_flush();
}
?>
爲什麼要跟着那麼多的人,它甚至成爲這樣的一個苦差事,你必須自動化它? – BoltClock
然後,您需要一個腳本來阻止所有來自您所關注的人的傳入推文。我在Twitter上追蹤用戶的 –
80%是朋友,所以我不介意看到我的時間表:) –