フォローされている人をフォローするスクリプト
<?php | |
error_reporting(-1); | |
set_time_limit(0); | |
require_once "./twitteroauth/twitteroauth/twitteroauth.php"; | |
$twitter = new TwitterOAuth( | |
{Consumer key}, | |
{Consumer secret}, | |
{Access token}, | |
{Access token secret} | |
); | |
$cursor = '-1'; | |
$friends = $twitter->OAuthRequest( | |
'http://api.twitter.com/1/followers/ids.json', | |
'GET', | |
array('cursor' => (string)$cursor) | |
); | |
$friends = json_decode($friends); | |
$results = array(); | |
foreach ($friends->ids as $user_id) { | |
$results[] = $user_id; | |
} | |
// フォローされた順にフォローしていきたい(なんとなく...)ので、reverse | |
$results = array_reverse($results); | |
foreach ($results as $user_id) { | |
$res = $twitter->OAuthRequest( | |
"http://api.twitter.com/1/friendships/create.xml", | |
"POST", | |
array('user_id' => "{$user_id}") | |
); | |
// 連続でAPI呼ぶとunfollowできないので、sleep入れてます | |
sleep(50); | |
echo "user_id: {$user_id} is follow!\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment