instagram api - cryptic response; not sure if working and unable to test omniauth with this

萝らか妹 提交于 2019-12-06 07:11:34

So, I have done a little research on Instagram API.

All the required info is located here: http://instagram.com/developer/authentication/

First of all, you need to get one-time CODE from Instagram. For your app it is pretty easy.

Just set href for your 'auth to instagram' link to:

"https://api.instagram.com/oauth/authorize/?client_id=4658fa17d45244c88dd13c73949a57d7&redirect_uri=http://seek-style.herokuapp.com/arc/services/instagram&response_type=code"

You will receive a redirect from API with CODE as a parameter.

You can handle it in services_controller#instagram or simply extract from application logs.

There should be something like

Processing by ServicesController#instagram as HTML
    Parameters: {"code"=>"c25dcdcb96ed4eb9a508fede0cb94e87", "state"=>"e3d6dc22d6cd3cdebf6fb9e51a728a120a6d901cc382c4bf"}

Then you should request an ACCESS_TOKEN from the API using cURL:

curl \-F 'client_id=YOUR_CLIENT_ID' \
-F 'client_secret=YOUR_CLIENT_SECRET' \
-F 'grant_type=authorization_code' \
-F 'redirect_uri= http://seek-style.herokuapp.com/arc/services/instagram' \
-F 'code=CODE_FROM_ABOVE' \https://api.instagram.com/oauth/access_token

Or using RestClient in services_controller#instagram :

resp = RestClient.post 'https://api.instagram.com/oauth/access_token', {
  client_id: 'YOUR_CLIENT_ID',
  client_secret: 'YOUR_CLIENT_SECRET',
  grant_type: 'authorization_code',
  redirect_uri: 'http://seek-style.herokuapp.com/arc/services/instagram',
  code: params[:code]
}

The cURL response or resp.body in controller should contain something like:

{
  "access_token":"1515660384.9f652d3.fcb1e712d41347069ad5c65ccfada994",
  "user":{
    "username":"petro.softserve",
    "bio":"",
    "website":"",
    "profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/anonymousUser.jpg",
    "full_name":"",
    "id":"1515660384"
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!