views:

807

answers:

3

Hi, I am trying to use oauth with the rares-branch Ruby gem. I keep getting the error:

instance of OAuth::Consumer needs to have method `marshal_load'

My code, activate.rb is below. Any thoughts on how to fix this? THANKS! -Henry

require 'oauth/consumer'

def index
  @consumer = OAuth::Consumer.new("CONSUMER KEY","CONSUMER SECRET", {
     :site => "http://api.netflix.com",
     :request_token_url => "https://api-user.netflix.com/oauth/request_token",
     :access_token_url => "http://api.netflix.com/oauth/access_token",
     :authorize_url => "https://api-user.netflix.com/oauth/login",
     :application_name => "AppName"})

  @request_token = @consumer.get_request_token

  session[:request_token]=@request_token
  session[:request_token_secret]=@request_token.secret

  @authorize_url = @request_token.authorize_url({
     :oauth_consumer_key => "CONSUMER KEY"
     :application_name => "AppName",
     :oauth_callback => "http://localhost:3000/activate/callback"
   })

  redirect_to @authorize_url
end

def callback
  @request_token=OAuth::RequestToken.new(session[:request_token],
  session[:request_token_secret])
  @access_token = @request_token.get_access_token

end
A: 

You need to have the user physically authorize it on the Netflix site. In this case, probably you. As I understand it, you can cache the token once you've gotten it from the manual authorization.

I was having similar problems with the Yammer API and never really got it sorted out. You may want to check out the Yammer API, Stammer, Ben Scofield did in Ruby that does handle the OAuth magic

Otto
+3  A: 

The token isn't serializable, so you can't store it in the session. Store the token key and secret individually in the session instead, and create a new OAuthToken with the key and secret when you need it again.

You may need to clear out your session store to get rid of the token that you already put in there.

Adam Hughes
A: 

I don't know if this is the best solution for this but this is how I got around it:

I aded the following code to my environment.rb:

class OAuth::Consumer
     def marshal_load(*args)
      self
    end

More of a hack, This would definitely fix the marshal load error. I don't know though if this would cause other problems.

jonasespelita