質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Facebook

Facebookは、実名登録制のSNS(ソーシャル・ネットワーキング・サービス)です。開発者用のデベロッパーサイトが存在し、一般ユーザーによるFacebook向けアプリケーション開発が可能です。

Q&A

0回答

1352閲覧

instgram apiについて

mizutama

総合スコア10

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Facebook

Facebookは、実名登録制のSNS(ソーシャル・ネットワーキング・サービス)です。開発者用のデベロッパーサイトが存在し、一般ユーザーによるFacebook向けアプリケーション開発が可能です。

0グッド

0クリップ

投稿2017/03/05 11:43

instgram apiについて

ruby言語で開発していて質問なのですが
このリクエストでエラーがでるのですが誰かこういうリクエストしたほうがいいよと分かる人がいましたら回答お願いします。
https://api.instagram.com/v1/users/search.json?access_token=himitsu&q=instagram

#使っているgemです
https://github.com/facebookarchive/instagram-ruby-gem

error内容

Instagram::BadRequest at /user_search GET https://api.instagram.com/v1/users/search.json?access_token=himitsu&q=instagram: 400: This request requires scope=public_content, but this access token is not authorized with this scope. The user must re-authorize your application with scope=public_content to be granted this permissions.

#使っているcodeです

require "sinatra" require "instagram" enable :sessions CALLBACK_URL = "http://localhost:4567/oauth/callback" Instagram.configure do |config| config.client_id = "" config.client_secret = "" # For secured endpoints only #config.client_ips = '<Comma separated list of IPs>' end get "/" do '<a href="/oauth/connect">Connect with Instagram</a>' end get "/oauth/connect" do redirect Instagram.authorize_url(:redirect_uri => CALLBACK_URL) end get "/oauth/callback" do response = Instagram.get_access_token(params[:code], :redirect_uri => CALLBACK_URL) session[:access_token] = response.access_token redirect "/nav" end get "/nav" do html = """ <h1>Ruby Instagram Gem Sample Application</h1> <ol> <li><a href='/user_recent_media'>User Recent Media</a> Calls user_recent_media - Get a list of a user's most recent media</li> <li><a href='/user_media_feed'>User Media Feed</a> Calls user_media_feed - Get the currently authenticated user's media feed uses pagination</li> <li><a href='/location_recent_media'>Location Recent Media</a> Calls location_recent_media - Get a list of recent media at a given location, in this case, the Instagram office</li> <li><a href='/media_search'>Media Search</a> Calls media_search - Get a list of media close to a given latitude and longitude</li> <li><a href='/media_popular'>Popular Media</a> Calls media_popular - Get a list of the overall most popular media items</li> <li><a href='/user_search'>User Search</a> Calls user_search - Search for users on instagram, by name or username</li> <li><a href='/location_search'>Location Search</a> Calls location_search - Search for a location by lat/lng</li> <li><a href='/location_search_4square'>Location Search - 4Square</a> Calls location_search - Search for a location by Fousquare ID (v2)</li> <li><a href='/tags'>Tags</a>Search for tags, view tag info and get media by tag</li> <li><a href='/limits'>View Rate Limit and Remaining API calls</a>View remaining and ratelimit info.</li> </ol> """ html end get "/user_recent_media" do client = Instagram.client(:access_token => session[:access_token]) user = client.user html = "<h1>#{user.username}'s recent media</h1>" for media_item in client.user_recent_media html << "<div style='float:left;'><img src='#{media_item.images.thumbnail.url}'><br/> <a href='/media_like/#{media_item.id}'>Like</a> <a href='/media_unlike/#{media_item.id}'>Un-Like</a> <br/>LikesCount=#{media_item.likes[:count]}</div>" end html end get '/media_like/:id' do client = Instagram.client(:access_token => session[:acces_token]) client.like_media("#{params[:id]}") redirect "/user_recent_media" end get '/media_unlike/:id' do client = Instagram.client(:access_token => session[:access_token]) client.unlike_media("#{params[:id]}") redirect "/user_recent_media" end get '/sample' do p 'iosdfjsdjfsfkjfjsd' puts session[:access_token] p 'iosdfjsdjfsfkjfjsd' insta = Instagram.client(:access_token => session[:access_token]) tags = insta.tag_search('cat') medias = [] 5.times do |i| medias.concat(insta.tag_recent_media(tags[i].name, { count: 30 })) end html = '' for media in medias html << "<img src='#{media.images.low_resolution.url}' style='width: 300px;'>" end html end get "/user_media_feed" do client = Instagram.client(:access_token => session[:acces_token]) user = client.user html = "<h1>#{user.username}'s media feed</h1>" page_1 = client.user_media_feed(777) page_2_max_id = page_1.pagination.next_max_id page_2 = client.user_recent_media(777, :max_id => page_2_max_id ) unless page_2_max_id.nil? html << "<h2>Page 1</h2><br/>" for media_item in page_1 html << "<img src='#{media_item.images.thumbnail.url}'>" end html << "<h2>Page 2</h2><br/>" for media_item in page_2 html << "<img src='#{media_item.images.thumbnail.url}'>" end html end get "/location_recent_media" do client = Instagram.client(:access_token => session[:access_token]) html = "<h1>Media from the Instagram Office</h1>" for media_item in client.location_recent_media(514276) html << "<img src='#{media_item.images.thumbnail.url}'>" end html end get "/media_search" do client = Instagram.client(:access_token => session[:acces_token]) html = "<h1>Get a list of media close to a given latitude and longitude</h1>" for media_item in client.media_search("37.7808851","-122.3948632") html << "<img src='#{media_item.images.thumbnail.url}'>" end html end get "/media_popular" do client = Instagram.client(:access_token => session[:access_token]) html = "<h1>Get a list of the overall most popular media items</h1>" for media_item in client.media_popular html << "<img src='#{media_item.images.thumbnail.url}'>" end html end get "/user_search" do client = Instagram.client(:access_token => session[:access_token]) html = "<h1>Search for users on instagram, by name or usernames</h1>" for user in client.user_search("instagram") html << "<li> <img src='#{user.profile_picture}'> #{user.username} #{user.full_name}</li>" end html end get "/location_search" do client = Instagram.client(:access_token => session[:access_token]) html = "<h1>Search for a location by lat/lng with a radius of 5000m</h1>" for location in client.location_search("48.858844","2.294351","5000") html << "<li> #{location.name} <a href='https://www.google.com/maps/preview/@#{location.latitude},#{location.longitude},19z'>Map</a></li>" end html end get "/location_search_4square" do client = Instagram.client(:access_token => session[:access_token]) html = "<h1>Search for a location by Fousquare ID (v2)</h1>" for location in client.location_search("3fd66200f964a520c5f11ee3") html << "<li> #{location.name} <a href='https://www.google.com/maps/preview/@#{location.latitude},#{location.longitude},19z'>Map</a></li>" end html end get "/tags" do client = Instagram.client(:access_token => session[:access_token]) html = "<h1>Search for tags, get tag info and get media by tag</h1>" tags = client.tag_search('cat') html << "<h2>Tag Name = #{tags[0].name}. Media Count = #{tags[0].media_count}. </h2><br/><br/>" for media_item in client.tag_recent_media(tags[0].name) html << "<img src='#{media_item.images.thumbnail.url}'>" end html end get "/limits" do client = Instagram.client(:access_token => session[:access_token]) html = "<h1/>View API Rate Limit and calls remaining</h1>" response = client.utils_raw_response html << "Rate Limit = #{response.headers[:x_ratelimit_limit]}. <br/>Calls Remaining = #{response.headers[:x_ratelimit_remaining]}" html end

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

CHERRY

2017/03/06 04:53

エラーメッセージに このアクセストークンには、権限がないと言われていますが、「scope=public_content」で、使えるアクセストークンでしょうか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問