Reputation: 1650
I'm trying out OAuth for twitter api authentication and ran into a brick wall when my code spits out the message:
(instance of OAuth::Consumer needs to have method `marshal_load')
My code:
@consumer=OAuth::Consumer.new( "token","secret", {
:site=>"http://mysite.com/"
})
@[email protected]_request_token
session[:request_token]=@request_token.token
session[:request_token_secret]=@request_token.secret
redirect_to @request_token.authorize_url
Errors are in the session assignment part. Clearing the session store doesn't correct the problem.
rake tmp:clear
Code works perfectly in irb but running it app-wise doesn't work. What could be the problem and solution to this?
Thanks!
Upvotes: 1
Views: 760
Reputation: 11
The same thing happened to me. It was because I had FIRST tried storing the entire token in my session:
session[:request_token]=@request_token
Then, I changed my code to only store the token(string) in the session:
session[:request_token]=@request_token.token
However, I was getting the same error as you
(instance of OAuth::Consumer needs to have method `marshal_load')
Because Rails was trying to look at what I have previously stored in my session (the entire token). Simply go into your browser's cookies and remove all of your cookies for your development host (mine was localhost). After that, try it again and everything should work fine.
Upvotes: 1
Reputation: 1650
After some googling around I came up with my own solution.
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.
Upvotes: 0
Reputation: 34774
I think it is the same problem as this question.
The answers there suggest that because the token isn't serializable it can't be retrieved from the session and that you should store the key in the session and create a new token from that and the secret.
Upvotes: 0