Note that there are some explanatory texts on larger screens.

plurals
  1. PO401 Unauthorized for foursquare OAuth
    text
    copied!<p>OK, I am pulling my hair after trying this out too many times to debug. So please help me out here. I keep getting <code>401 Unauthorized error</code> after I am redirected back.</p> <p>Here is my code. What am I doing wrong here?</p> <pre><code>require 'rubygems' require 'OAuth' require 'json' class SessionController &lt; ApplicationController before_filter :load_oauth def index if session[:request_token] &amp;&amp; params[:oauth_token] @request_token = OAuth::RequestToken.new(@consumer, session[:request_token], session[:request_secret]) @access_token = @request_token.get_access_token(:oauth_verifier =&gt; params[:oauth_verifier]) puts @access_token @info = @access_token.get("http://api.foursquare.com/v1/ test") flash[:notice] = "Foursquare! Yay!" else redirect_to(@foursqrurl) end end private def load_oauth @oauth_key = 'key' @oauth_secret = 'secret' @consumer = OAuth::Consumer.new(@oauth_key,@oauth_secret,{ :site =&gt; "http://foursquare.com", :scheme =&gt; :header, :http_method =&gt; :post, :request_token_path =&gt; "/oauth/request_token", :access_token_path =&gt; "/oauth/access_token", :authorize_path =&gt; "/oauth/authorize" }) @request_token = @consumer.get_request_token(:oauth_callback =&gt; "http://localhost:3001/session") session[:request_token] = @request_token.token session[:request_secret] = @request_token.secret puts @request_token.token puts @request_token.secret # redirecting user to foursquare to authorize @foursqrurl = @request_token.authorize_url puts @foursqrurl end end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload