instagram api – 神秘的回应; 不确定是否工作,无法用此测试omniauth
我正在开发一个rails应用程序,其中要求使用omniuth登录到instagram。 这将是我第一次使用instagrams OAuth端点,并且不清楚它是否正常工作(并且对项目经理也不清楚)。 我正在使用他们的cURL实现以下(将来会重置它),但得到“找不到匹配的代码”错误,这似乎是逻辑上的第一个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
有回应
{"code": 400, "error_type": "OAuthException", "error_message": "No matching code found."}
我做的事情显然是错的吗? 有完成的例子说明如何完成这项工作? 我见过https://github.com/ropiku/omniauth-instagram,但不知道是否还在工作。 Spec的传递,但实际的调用被嘲笑。
谢谢
编辑#1
根据评论,我添加了一个链接到repo https://github.com/trestles/seek ,用于部署到heroku。 在应用程序中基本上没有任何内容,而且根据我的知识,上面的cURL应该正常工作(而不是)所以我甚至都没有测试过这个。 也许我甚至误解了Instagram的API是如何工作的。
所以,我对Instagram API做了一些研究。
所有必需的信息都位于: http : //instagram.com/developer/authentication/
首先,你需要从Instagram获得一次性CODE 。 对于您的应用程序,这很容易。
只需将“auth to instagram”链接设置为href
即可:
"https://api.instagram.com/oauth/authorize/?client_id=4658fa17d45244c88dd13c73949a57d7&redirect_uri=http://seek-style.herokuapp.com/arc/services/instagram&response_type=code"
您将收到来自API的重定向,其中CODE作为参数 。
您可以在services_controller#instagram
处理它,或者只是从应用程序日志中提取。
应该有类似的东西
Processing by ServicesController#instagram as HTML Parameters: {"code"=>"c25dcdcb96ed4eb9a508fede0cb94e87", "state"=>"e3d6dc22d6cd3cdebf6fb9e51a728a120a6d901cc382c4bf"}
然后,您应该使用cURL 从API请求ACCESS_TOKEN :
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
或者在services_controller#instagram
使用RestClient:
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] }
控制器中的cURL响应或resp.body
应包含以下内容:
{ "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" } }