Ruby-on-rails Oauth2 Instagram API“重定向 URI 与注册的重定向 URI 不匹配”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16537721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oauth2 Instagram API "redirect URI does not match registered redirect URI"
提问by Biketire
I am working on a Rails application which is in development mode and it can register with omniauth.
我正在开发一个处于开发模式的 Rails 应用程序,它可以向 omniauth 注册。
The host is
主持人是
http://localhost:3000/
I'm using the gems:
我正在使用宝石:
gem 'omniauth'
gem 'omniauth-foursquare'
gem 'omniauth-instagram'
When I register through omniauth with Foursquare there's no problem at all. All the settings are right and my redirect_uri in the Foursquare developer settings equals to the host (localhost:3000)
当我通过 omniauth 注册 Foursquare 时,完全没有问题。所有设置都正确,我在 Foursquare 开发人员设置中的 redirect_uri 等于主机(本地主机:3000)
However, if I fill in the exact same redirect_uri (localhost:3000) in the Instagram client manager*. Instagram gives me this:
但是,如果我在 Instagram 客户端管理器中填写完全相同的 redirect_uri (localhost:3000)*。Instagram给了我这个:
{
"code": 400,
"error_type": "OAuthException",
"error_message": "Redirect URI does not match registered redirect URI"
}
Based upon this URL:
基于此 URL:
https://instagram.com/oauth/authorize?response_type=code&client_id=<ID>&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Finstagram%2Fcallback&state=18415adf24dd97873e61094f67c0fb7a94857fedf93e9d2e&scope=basic
*

*

What am I doing wrong according to Instagram and how should this be fixed?
根据 Instagram,我做错了什么,应该如何解决?
回答by Biketire
Fixed the issue myself. Added localhost:3000/auth/instagram/callbackas redirect_uri and it worked just fine.
自己解决了这个问题。添加localhost:3000/auth/instagram/callback为redirect_uri,它工作得很好。
回答by rubygrrl42
I needed to add
我需要添加
http://localhost:3000/users/auth/instagram/callback
as my callback URI because I'm using Devise.
作为我的回调 URI,因为我使用的是 Devise。
回答by Dylan Fisher
When you specify a redirect URI http://localhost:3000is not the same as http://localhost:3000/(note the trailing slash).
当您指定重定向 URI 时,http://localhost:3000与http://localhost:3000/ 不同(注意尾部斜杠)。
Make sure the callback URI matches exactly.
确保回调 URI 完全匹配。
回答by Rohit Kaushik
{"error_type": "OAuthException", "code": 400, "error_message": "Redirect URI does not match registered redirect URI"}
{"error_type": "OAuthException", "code": 400, "error_message": "重定向 URI 与注册的重定向 URI 不匹配"}
How to get Access token from instagram
如何从 Instagram 获取访问令牌
Your website url must be same when registering sandbox clien api on instagram https://www.instagram.com/developer/
在 instagram https://www.instagram.com/developer/上注册沙盒客户端 api 时,您的网站 url 必须相同
here we used website url: https://adlivetech.comValid redirect URIs: https://adlivetech.com/
这里我们使用了网站 url:https: //adlivetech.com有效的重定向 URI:https: //adlivetech.com/
For live website you can get Access token easily by using https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token
对于实时网站,您可以使用https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token轻松获取访问令牌
Replace above url "CLIENT-ID" with your client ID Replace above url "REDIRECT-URI" redirect url should be your domain name like: http://adlivetech.com
将上面的 url "CLIENT-ID" 替换为您的客户端 ID 替换上面的 url "REDIRECT-URI" 重定向 url 应该是您的域名,例如:http: //adlivetech.com
回答by Julian
I mucked around with this for ages.. perhaps it has changed but: http://localhost:3000/users/auth/instagram/int_callbackwas the callback URI that finally worked for me. The ONLY issue i was having was that it was exactly an incorrect callback uri and wish I had seen here that I should be focusing on my Instagram setup instead of modifying my code.. to get the error message means everything else is working (so far), otherwise you would not be getting that particular error message. Good luck!! - don't get distracted!
我一直在纠结这个问题……也许它已经改变了,但是: http://localhost:3000/users/auth/instagram/int_callback是最终对我有用的回调 URI。我遇到的唯一问题是它完全是一个不正确的回调 uri,希望我在这里看到我应该专注于我的 Instagram 设置而不是修改我的代码.. 获取错误消息意味着其他一切都在工作(到目前为止),否则您将不会收到该特定错误消息。祝你好运!!- 不要分心!
回答by Chris D. Emerson
This isn't a ruby-specific but for anyone else wrestling w/this here's what got me past it (note: nothing in above answers worked for me):
这不是特定于 ruby 的,但对于其他任何与此搏斗的人来说,这就是让我过去的原因(注意:上述答案中没有任何内容对我有用):
1. Edit your Client on Instagram Developer and uncheck Disable implicit OAuth.2. Click Update Client to save it.3. Now go to https://instagram.com/oauth/authorize/?client_id=[CLIENT_ID]&redirect_ur.... Just change [CLIENT_ID] and [REDIRECT_URI] with their values.4. After that you will be redirected to [REDIRECT_URI]/#access_token=[ACCESS_TOKEN]. Get it and place it on the Instagram Access Token textbox.
1. Edit your Client on Instagram Developer and uncheck Disable implicit OAuth.2. Click Update Client to save it.3. Now go to https://instagram.com/oauth/authorize/?client_id=[CLIENT_ID]&redirect_ur.... Just change [CLIENT_ID] and [REDIRECT_URI] with their values.4. After that you will be redirected to [REDIRECT_URI]/#access_token=[ACCESS_TOKEN]. Get it and place it on the Instagram Access Token textbox.
(Source: https://www.drupal.org/project/instagram_feeds/issues/2140479)
(来源:https: //www.drupal.org/project/instagram_feeds/issues/2140479)
回答by CIRCLE
For anyone that is having this issue and the redirect uri provided to instagram is exactly the same as the one you're using, i've found that some users were typing my website address as http://www.example.com/loginwhen in my instagram api it was http://example.com/login.
对于遇到此问题并且提供给 instagram 的重定向 uri 与您正在使用的 uri 完全相同的任何人,我发现有些用户正在输入我的网站地址,就像http://www.example.com/login在我的 instagram api 中一样http://example.com/login。
Then I created a php script to detect if the string wwwexists in my url and then reload to the same page but without the www.
然后我创建了一个 php 脚本来检测字符串是否www存在于我的 url 中,然后重新加载到同一页面但没有www.
if(strpos($_SERVER['HTTP_HOST'], 'www.') !== FALSE) {
header("Location: ".str_replace('www.', '', $_SERVER['HTTP_HOST'].'/'.$_SERVER['REQUEST_URI']));
}
回答by Sergey Zhukov
For Drupagram module (Drupal 7) added: http://localhost:3000/instagram/oauthas redirect_uri
对于 Drupagram 模块(Drupal 7)添加:http://localhost:3000/instagram/oauth作为 redirect_uri
回答by Narendrakumar
Issue: Oauth2 Instagram API “redirect URI does not match registered redirect URI
问题:Oauth2 Instagram API“重定向 URI 与注册的重定向 URI 不匹配
My Solution: Please check ng-cordova-oauth.js file and check instagram function in that. Verify redirect_uri value is same as register your application on developer console for Instagram.If it is same it works properly,otherwise you get the above issue.
我的解决方案:请检查 ng-cordova-oauth.js 文件并检查其中的 instagram 功能。验证redirect_uri 值是否与在Instagram 的开发者控制台上注册您的应用程序相同。如果相同,则可以正常工作,否则会出现上述问题。
回答by Nino Paolo
...Or you can follow the instructions here:
...或者您可以按照此处的说明进行操作:
https://instagram.com/developer/authentication/?hl=en
https://instagram.com/developer/authentication/?hl=en
See "Step One: Direct your user to our authorization URL" section.
请参阅“第一步:将您的用户定向到我们的授权 URL”部分。
Just simply supply your CLIENT_ID and REDIRECT_URI.
只需提供您的 CLIENT_ID 和 REDIRECT_URI。
https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code

