Oauth2 Instagram API“重定向URI与注册的重定向URI不匹配”

时间:2013-05-14 07:47:51

标签: ruby-on-rails oauth-2.0 omniauth instagram

我正在开发一个处于开发模式的Rails应用程序,它可以注册omniauth。

主持人

http://localhost:3000/

我正在使用宝石:

gem 'omniauth'
gem 'omniauth-foursquare'
gem 'omniauth-instagram'

当我通过Foursquare注册omniauth时,根本没有问题。所有设置都是正确的,我在Foursquare开发人员设置中的redirect_uri等于主机(localhost:3000)

但是,如果我在Instagram客户经理*中填写完全相同的redirect_uri(localhost:3000)。 Instagram给了我这个:

{
 "code": 400,
 "error_type": "OAuthException",
 "error_message": "Redirect URI does not match registered             redirect URI"
}

基于此网址:

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

* enter image description here

根据Instagram,我做错了什么,应该如何解决?

10 个答案:

答案 0 :(得分:23)

我自己解决了这个问题。添加了localhost:3000/auth/instagram/callback作为redirect_uri,它运行得很好。

答案 1 :(得分:8)

我需要添加

http://localhost:3000/users/auth/instagram/callback

作为我的回调URI,因为我正在使用Devise。

答案 2 :(得分:5)

指定重定向URI http://localhost:3000http://localhost:3000/不同(请注意尾部斜杠)。

确保回调URI完全匹配。

答案 3 :(得分:0)

对于Drupagram模块(Drupal 7)添加:http://localhost:3000/instagram/oauth as redirect_uri

答案 4 :(得分:0)

对于遇到此问题并且提供给Instagram的重定向uri与您正在使用的重定向完全相同的任何人,我发现有些用户在我的网站上输入的地址为http://www.example.com/login instagram api它是http://example.com/login

然后我创建了一个php脚本来检测我的网址中是否存在字符串www,然后重新加载到同一页面但没有www

if(strpos($_SERVER['HTTP_HOST'], 'www.') !== FALSE) {
    header("Location: ".str_replace('www.', '', $_SERVER['HTTP_HOST'].'/'.$_SERVER['REQUEST_URI']));
}

答案 5 :(得分:0)

问题:Oauth2 Instagram API“重定向URI与注册的重定向URI

不匹配

我的解决方案:请检查ng-cordova-oauth.js文件并检查其中的instagram功能。验证redirect_uri值与在Instagram的开发者控制台上注册您的应用程序相同。如果它是相同的,它可以正常工作,否则您会遇到上述问题。

答案 6 :(得分:0)

{&#34; error_type&#34;:&#34; OAuthException&#34;,&#34; code&#34;:400,&#34; error_message&#34;:&#34;重定向URI不匹配已注册的重定向URI&#34;}

如何从Instagram获取访问令牌

在Instagram https://www.instagram.com/developer/上注册sandbox clien api时,您的网站网址必须相同

这里我们使用了网址网址:https://adlivetech.com 有效的重定向URI:https://adlivetech.com/

对于实时网站,您可以使用https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token

轻松获取访问令牌

替换上面的网址&#34;客户端ID&#34;使用您的客户ID 替换上面的网址&#34; REDIRECT-URI&#34;重定向网址应该是您的域名,如:http://adlivetech.com

https://adlivetech.com/access_token=YOUR_ACCESS_TOken

答案 7 :(得分:0)

我用这种方法捣乱了很久.. 也许它已经改变但是: http://localhost:3000/users/auth/instagram/int_callback 是最终为我工作的回调URI。 我唯一的问题是,这是一个不正确的回调uri,并希望我在这里看到我应该专注于我的Instagram设置而不是修改我的代码..获取错误消息意味着其他一切正常工作(到目前为止) ),否则你不会得到那个特定的错误信息。 祝好运!! - 不要分心!

答案 8 :(得分:0)

这不是特定于红宝石的,但对于其他任何人来说,这就是让我超越它的原因(注意:以上答案中没有任何内容适用于我):

  • 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.

(资料来源:https://www.drupal.org/project/instagram_feeds/issues/2140479

答案 9 :(得分:-1)

...或者您可以按照此处的说明操作:

https://instagram.com/developer/authentication/?hl=en

请参阅&#34;第一步:将用户引导至我们的授权网址&#34;部分。

只需提供您的CLIENT_ID和REDIRECT_URI。

https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code