Created
July 19, 2012 13:51
-
-
Save ojimac/3144061 to your computer and use it in GitHub Desktop.
フォローされている人をフォローするスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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