Search code examples
oauthtumblr

Tumblr OAuth Callback URL


I'm setting the oauth_callback URL in the request header, when I do this in Twitter, it works fine and the user is redirected to the callback URL. But using Tumblr's API, the callback URL is ignored and the user is redirected to the default URL. Has anybody else experienced this? Is there anywhere else other than the header that I should be setting this? I tried passing it in as a parameter but that didn't really work either.

Any help would be appreciated.


Solution

  • If you are trying a embed userid in callback url then this post can help you.
    You can save your oauth token in a session and later on callback you can retrieve user from session.

    on token request:

    def ask_access
      tumblr_consumer = get_consumer
      if tumblr_consumer
        #1. get a request token
        request_token = tumblr_consumer.get_request_token
        session[:request_token] = request_token
        session[:user_token] = "#{request_token.params[:oauth_token]}_#{current_user.id}"
        #2. have the user authorize
        redirect_to request_token.authorize_url
      else
        render :text=> "Failed to acquire request token from Tumblr."
      end
    end
    

    on call back:

    def call_back
      if params[:oauth_token] && params[:oauth_verifier]
        request_token = session[:request_token]
        user_id  = session[:user_token].split("_")[1]
        user = UserProfile.find user_id
        ##3. get an access token
        access_token = request_token.get_access_token({:oauth_verifier => params[:oauth_verifier]})
        user.tumblr_token = access_token.params[:oauth_token]
        user.tumblr_secret = access_token.params[:oauth_token_secret]
        user.save!
      end
    end