4

我正在尝试将 oauth 与稀有分支 Ruby gem 一起使用。我不断收到错误:

OAuth::Consumer 的实例需要有方法“marshal_load”

我的代码 activate.rb 如下。关于如何解决这个问题的任何想法?谢谢!-亨利

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
4

3 回答 3

5

令牌不可序列化,因此您不能将其存储在会话中。相反,将令牌密钥和秘密单独存储在会话中,并在您再次需要时使用密钥和秘密创建一个新的 OAuthToken。

您可能需要清除会话存储以摆脱已放入其中的令牌。

于 2009-03-23T19:57:19.513 回答
0

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

于 2009-01-24T16:21:55.110 回答
0

我不知道这是否是最好的解决方案,但这就是我解决它的方法:

我在 environment.rb 中添加了以下代码:

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

更多的 hack,这肯定会修复 marshal 加载错误。我不知道这是否会导致其他问题。

于 2009-10-09T00:59:51.647 回答