Created
April 6, 2018 04:05
-
-
Save nownabe/202854eefce253d8eda0c4f79f1a645f to your computer and use it in GitHub Desktop.
Instagram GraphQL API
This file contains hidden or 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
# frozen_string_literal: true | |
require "faraday" | |
require "faraday_middleware" | |
endpoint = "https://www.instagram.com/graphql/query/" | |
# query_hash = "42323d64886122307be10013ad2dcc44" | |
# variables = '{"id":"3872941487","first":12,"after":"AQANkBj-f-ZzmLfmYiXU6qjC7nnHbpPttpppOPrL-i6mESM7hl04zzC50sCvA-RC3PFI98BtktoArwP9Ani1Z4dY067A1S6xvvhFqfgyJXJ5qw"}' | |
# csrf_token = "HIzZV98ydKLQmM6hGTtovnlqnrFwhsDf" | |
# referer = "https://www.instagram.com/sunny_rei_32/?hl=ja" | |
# user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.3" | |
conn = Faraday.new(url: endpoint) do |f| | |
f.request :url_encoded | |
f.response :logger | |
f.response :json, content_type: /\bjson$/ | |
f.adapter Faraday.default_adapter | |
end | |
# params = { | |
# query_hash: query_hash, | |
# variables: variables, | |
# } | |
params = { | |
query_id: 17888483320059182, # Fixed value | |
id: 3872941487, # User ID | |
first: 12, | |
after: "AQANkBj-f-ZzmLfmYiXU6qjC7nnHbpPttpppOPrL-i6mESM7hl04zzC50sCvA-RC3PFI98BtktoArwP9Ani1Z4dY067A1S6xvvhFqfgyJXJ5qw" # Paging | |
} | |
headers = { | |
# cookie: "csrftoken=#{csrf_token};", | |
} | |
resp = conn.get do |req| | |
req.params = params | |
req.headers = headers | |
end | |
puts "==== response status ====" | |
puts resp.status | |
puts | |
puts "==== response ====" | |
resp.body["data"]["user"]["edge_owner_to_timeline_media"]["edges"].each do |edge| | |
puts "#{edge["node"]["id"]}: #{edge["node"]["thumbnail_src"]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment