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

不羁的心 提交于 2019-12-22 18:24:20

问题


I am working on an rails app that has as the requirement logging in with omniuth to instagram. This would be my first time using instagrams OAuth endpoint and it is unclear whether it is working (and not clear to project manager either). I'm using their cURL implementation with the following (will reset it in future) but getting "No matching code found" error which would seem to be the logical first setp.

curl \-F 'client_id=4658fa17d45244c88dd13c73949a57d7' \
    -F 'client_secret=ae6cfe5d13544eada4dece2ec40ac5dc' \
    -F 'grant_type=authorization_code' \
    -F 'redirect_uri= http://seek-style.herokuapp.com/arc/services/instagram' \
    -F 'code=CODE' \https://api.instagram.com/oauth/access_token

with response

{"code": 400, "error_type": "OAuthException", "error_message": "No matching code found."}

Is there something that I am doing obviously wrong? Is there a finished example of how to get this done? I have seen https://github.com/ropiku/omniauth-instagram but can't tell if still working. Spec's pass but the actual call is mocked.

thx

edit #1

per comments, I have added a link to repo https://github.com/trestles/seek that is being used to deploy to heroku. There's basically nothing in the app and the above cURL to the best of my knowledge should be working (and isn't) so I havne't really even tested this. Perhaps I'm misunderstanding even how Instagram's API is working.


回答1:


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"
  }
}


来源:https://stackoverflow.com/questions/25986296/instagram-api-cryptic-response-not-sure-if-working-and-unable-to-test-omniaut

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!