如何处理用户在rails中撤销LinkedIn访问权限

时间:2013-03-14 04:10:47

标签: ruby-on-rails oauth omniauth linkedin

如何处理用户撤销对其LinkedIn帐户的访问权限?我使用Ruby on Rails与OmniauthOmniauth-LinkedInlinkedin gem(后者合并oauth gem)。

我的控制器代码

if !@user[:lnk_token].nil?
  client = LinkedIn::Client.new("xxxx","xxxx")
  client.authorize_from_access(@user[:lnk_token].strip,@user[:lnk_access_token_secret].strip)
  @lnk = client.profile(:fields => ["picture-url", "positions", "educations"])
end

1 个答案:

答案 0 :(得分:0)

使用简单的错误处理程序:

if !@user[:lnk_token].nil?
  client = LinkedIn::Client.new("xxxx","xxxx")
  client.authorize_from_access(@user[:lnk_token].strip,@user[:lnk_access_token_secret].strip)
  begin
    @lnk = client.profile(:fields => ["picture-url", "positions", "educations"])
  rescue
    @lnk = nil
  end
end

进一步阅读:http://rubylearning.com/satishtalim/ruby_exceptions.html