Skip to content

Instantly share code, notes, and snippets.

@dmpatierno
Created May 15, 2011 03:54
Show Gist options
  • Save dmpatierno/972873 to your computer and use it in GitHub Desktop.
Save dmpatierno/972873 to your computer and use it in GitHub Desktop.
unfollow all users on tumblr
<?php
$cookie = "<insert cookies>";
$token = null;
do {
$users = get_users();
foreach ($users as $user)
unfollow($user);
} while (count($users));
echo "done\n";
function get_users($page = 1) {
global $cookie, $token;
$url = "http://www.tumblr.com/following";
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_COOKIE => $cookie
));
$response = curl_exec($ch);
preg_match_all('/unfollow_button_[^"]+" data-name="([^"]+)" data-formkey="([^"]+)"/', $response, $m);
$token = $m[2][0];
return $m[1];
}
function unfollow($user) {
global $cookie, $token;
$url = 'http://www.tumblr.com/svc/unfollow';
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_COOKIE => $cookie,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => "form_key={$token}&data[tumblelog]={$user}&data[source]=FOLLOW_SOURCE_FOLLOWING_PAGE"
));
$response = curl_exec($ch);
echo "unfollow {$user}\n";
}
@RaflH
Copy link

RaflH commented Aug 30, 2011

How can I use this in chrome?

@dmpatierno
Copy link
Author

It's a PHP script. You'll need to set your cookie on line 3 and run it from the command line.

@RaflH
Copy link

RaflH commented Aug 30, 2011

Couple more questions-
what's a cookie?
command line = terminal?

@harshey
Copy link

harshey commented Dec 15, 2011

Hi dmpatierno,

I'm running this from my server. What do I put in line 3? Do I need to put in a cookie from Tumblr? It puts 11 cookies on my browser. Which one should I put?

Help much appreciated.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment