forked from abraham/twitteroauth
-
Notifications
You must be signed in to change notification settings - Fork 0
Victor Stan edited this page May 5, 2013
·
2 revisions
<?php
require_once 'lib/twitteroauth.php';
define('CONSUMER_KEY', 'your_consumer_key');
define('CONSUMER_SECRET', 'your_consumer_secret');
define('ACCESS_TOKEN', 'your_access_token');
define('ACCESS_TOKEN_SECRET', 'your_access_token_secret');
function autoFollow()
{
$toa = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$followers = $toa->get('followers/ids', array('cursor' => -1));
$followerIds = array();
foreach ($followers->ids as $i => $id) {
$followerIds[] = $id;
if ($i == 99) break; // Deal with only the latest 100 followers.
}
$friends = $toa->get('friends/ids', array('cursor' => -1));
$friendIds = array();
foreach ($friends->ids as $i => $id) {
$friendIds[] = $id;
if ($i == 99) break; // Deal with only the latest 100 friends.
}
foreach ($followerIds as $id) {
if (empty($friendIds) or !in_array($id, $friendIds)) {
$ret = $toa->post('friendships/create', array('user_id' => $id));
}
}
}
autoFollow();