{"code": 400, "error_type": "OAuthException", "error_message": "Redirect URI does not match registered redirect URI"} in Rails
<p>I am  having a photo upload scenario where when I click on link, it has to goto Instagram and upload pictures from there. But I am facing the following issue:</p>

<blockquote>
  <p>{"code": 400, "error_type": "OAuthException", "error_message":
  "Redirect URI does not match registered redirect URI"}</p>
</blockquote>

<p>This is the redirected url when I click on link :</p>

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

<p>This is my code:</p>

<p>routes.rb:</p>

<pre><code>get "/instagram/callback" =&gt; "photos#instagram_callback"
</code></pre>

<p>photos_controller:</p>

<pre><code>class PhotosController &lt; ApplicationController
  before_filter :check_for_errors, :only =&gt; [:instagram_callback]
  def instagram_callback
    response = Instagram.get_access_token(params[:code], :redirect_uri =&gt; 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 =&gt; true)
    else
      redirect_to new_user_report_path(current_user, :ig =&gt; true)
    end
  end
end
</code></pre>

<p>views/_photos.html.erb:</p>

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

<p>Please help.                                                                                                                                                                                                                                                                                                                                    </p>