{"代码":400," error_type":" OAuthException"," error_message":"重定向URI与注册的重定向不匹配Rails

时间:2016-10-07 11:54:16

标签: ruby-on-rails instagram

我正在进行照片上传方案,当我点击链接时,它必须转到Instagram并从那里上传图片。但我面临以下问题:

  

{"代码":400," error_type":" OAuthException"," error_message":   "重定向URI与注册的重定向URI"}

不匹配

当我点击链接时,这是重定向的网址:

https://www.instagram.com/oauth/authorize/?client_id=CLIENT_ID&redirect_uri=http://localhost:3000/instagram/callback/?edit=&response_type=code 

这是我的代码:

routes.rb中:

get "/instagram/callback" => "photos#instagram_callback"

photos_controller:

class PhotosController < ApplicationController
  before_filter :check_for_errors, :only => [:instagram_callback]
  def instagram_callback
    response = Instagram.get_access_token(params[:code], :redirect_uri => Rails.application.config.custom.domain_url + 'instagram/callback/?edit=' + (params[:edit].present? ? params[:edit] : ''))
    oauth = OauthAccessToken.find_or_create_by_provider_and_user_id('instagram', current_user.id)
    oauth.access_token = response.access_token
    oauth.save
    if params[:edit].present?
      redirect_to edit_user_report_path(current_user, params[:edit], :ig => true)
    else
      redirect_to new_user_report_path(current_user, :ig => true)
    end
  end
end

视图/ _photos.html.erb:

<% if @instagram_oauth.nil? %>
  <%= link_to '', Instagram.authorize_url(:redirect_uri => Rails.application.config.custom.domain_url + 'instagram/callback/?edit=' + (params[:id].present? ? params[:id] : ''))%>
<% end %>

请帮忙。

2 个答案:

答案 0 :(得分:0)

您需要在http://localhost:3000/instagram/callback/上为您的申请注册redirect_uri“instagram developer portalMore information关于redirect_uri

答案 1 :(得分:0)

https://www.instagram.com/developer/authentication/

必须通过https拨打电话。不知道它们会导致此错误,但是您在instagram网址中显示http。