Created
July 11, 2013 13:38
-
-
Save ragekit/5975512 to your computer and use it in GitHub Desktop.
Easy way to backup your tumblr likes
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
require "oauth" | |
require 'json' | |
require 'uri' | |
#CONFIG : | |
oauthConsumer = "consumerkey" | |
oauthSecret ="consumersecret" | |
tumblrUsername="mail" | |
tumblrPass="password" | |
#the folder you want to save images relative to script | |
savefolder = "images/" | |
# BEGIN SCRIPT : | |
@consumer = OAuth::Consumer.new oauthConsumer, | |
oauthSecret, | |
{:site =>'https://www.tumblr.com'} | |
@access_token = @consumer.get_access_token nil, | |
{}, | |
{ :x_auth_mode => 'client_auth', | |
:x_auth_username => tumblrUsername, | |
:x_auth_password => tumblrPass | |
} | |
offset = 0 | |
fileNb=0 | |
if !FileTest::directory?(savefolder) | |
Dir::mkdir(savefolder) | |
end | |
while true | |
response = @access_token.get("http://api.tumblr.com/v2/user/likes?offset="+offset.to_s) | |
body = JSON.load response.body | |
#puts body; | |
puts "----------------------------" | |
if body["response"]["liked_posts"].empty? == true | |
break | |
end | |
likes = body["response"]["liked_posts"] | |
likes.each do |like| | |
if like["type"] == "photo" | |
folder = like["blog_name"]+"/" | |
photoset = like["photos"] | |
fileNb+=1 | |
photoset.each do |photos| | |
#might be several photos in like | |
uri = URI(photos["original_size"]["url"]) | |
filename = uri.path[1,uri.path.length-1] | |
if filename.rindex("/") != nil then | |
filename = filename[filename.rindex("/")+1, filename.length] | |
end | |
if(!File.exist?(savefolder+folder+filename)) then | |
puts "downloading file " + fileNb.to_s + " : " + filename | |
resp = Net::HTTP.get_response(uri) | |
if resp.code != "200" | |
then puts resp.code | |
end | |
#check if directory exists | |
if !FileTest::directory?(savefolder+folder) | |
Dir::mkdir(savefolder+folder) | |
end | |
open(savefolder+folder+filename, "wb") { |file| | |
file.write(resp.body) | |
} | |
end | |
end | |
end | |
end | |
offset +=20 | |
end | |
puts "complete !" |
/Library/Ruby/Gems/2.0.0/gems/oauth-0.5.1/lib/oauth/consumer.rb:217:in `token_request': 400 Bad Request (OAuth::Unauthorized)
from /Library/Ruby/Gems/2.0.0/gems/oauth-0.5.1/lib/oauth/consumer.rb:106:in `get_access_token'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes. Same error for me. Wasn't sure what to put for "Default callback URL" tho