Skip to content

Instantly share code, notes, and snippets.

@mysteriouspants
Last active August 29, 2015 14:18
Show Gist options
  • Save mysteriouspants/43f5ff14c47fd1078583 to your computer and use it in GitHub Desktop.
Save mysteriouspants/43f5ff14c47fd1078583 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'net/https'
require 'json'
require 'pry'
$client_id = 'lol'
$client_secret = 'its a freakin secret man!'
user = 'DeadpoolSupplier'
page = 0
# login
def login(conn)
uri = URI("https://api.imgur.com/oauth2/authorize")
uri.query = URI.encode_www_form({
response_type: :pin,
client_id: $client_id,
state: :panic
})
system("start #{uri.to_s.gsub('&','^&')}")
puts "please input PIN: "
pin = gets.chomp
nuri = URI("https://api.imgur.com/oauth2/token")
req = Net::HTTP::Post.new(nuri)
req.set_form_data({
client_id: $client_id,
client_secret: $client_secret,
grant_type: :pin,
pin: pin
})
res = conn.request(req)
if res.is_a?(Net::HTTPSuccess)
response_structure = JSON.parse(res.body)
return response_structure['access_token']
else
raise "something's fucky"
end
end
uri = URI("https://api.imgur.com/")
conn = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true)
conn.set_debug_output($stdout)
access_token = login(conn)
uri = URI("https://api.imgur.com/3/account/#{user}/images/")
req = Net::HTTP::Get.new(uri)
req['Authorization'] = "Bearer #{access_token}"
res = conn.request(req)
puts res.body
# res 403's me and tells me that I can't get a list of images uploaded by a user?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment