Skip to content

Instantly share code, notes, and snippets.

@ebibibi
Created July 6, 2012 15:40
Show Gist options
  • Select an option

  • Save ebibibi/3060973 to your computer and use it in GitHub Desktop.

Select an option

Save ebibibi/3060973 to your computer and use it in GitHub Desktop.
get instagram picture url from page of instagram.
require 'rubygems'
require 'net/http'
require 'uri'
require 'json'
class ExpandUrl
def self.expand_url(url)
uri = url.kind_of?(URI) ? url : URI.parse(url)
Net::HTTP.start(uri.host, uri.port) { |io|
r = io.head(uri.path)
r['Location'] || uri.to_s
}
end
end
class Instagram
def self.isInstagram?(url)
if url =~ /http:\/\/instagr\.am\/.*/
return true
end
begin
url = ExpandUrl.expand_url(url)
if url =~ /http:\/\/instagr\.am\/.*/
return true
end
rescue
return false
end
false
end
def self.imgsrc(url)
if (!(url =~ /http:\/\/instagr\.am\/.*/))
url = ExpandUrl.expand_url(url)
end
host = host = "api.instagram.com"
page = "/oembed?url=" + url
insta = JSON.parse(Net::HTTP.get(host, page))
insta['url']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment