Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Follow another user's friends list using GS API (Will not work with Mastodon friends)
<?php
/*
By Mitchell Urgero (@stitchxd@p2px.me)
Mass follower using a friends.json list. Based off of https://gitlab.com/snippets/12852
(Looks like the api will only grab 201 "friends" at a time.... shame really...)
*/
$user = "user";
$pass = "P@ssW0Rd";
$api = "https://example.com/api";
//Call start(..) with the api url's of peoples lists you want to scrape.
start("https://example.com","someuser1");
start("https://example.com","someuser2");
//Do not edit past this point...
function start($url, $name){
$friendJSON = file_get_contents($url."/api/statuses/friends.json?screen_name=$name&count=9999");
$friendPHP = json_decode($friendJSON, true);
echo count($friendPHP)." users to follow in this list...\r\n";
$i = 1;
foreach($friendPHP as $f){
echo "$i: ".$f['statusnet_profile_url']."\r\n";
followUser($f['statusnet_profile_url']);
$i++;
sleep(3);
}
}
function followUser($url){
global $user, $pass, $api;
$statusUrl = $api."/statuses/update.json";
$POST = array(
"status" => "follow ".$url
);
$fields_string = '';
foreach($POST as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $statusUrl);
curl_setopt($ch,CURLOPT_POST, count($POST));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo "\r\n";
echo $output."\r\n";
return;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment