如何处理用户撤销对其LinkedIn帐户的访问权限?我使用Ruby on Rails与Omniauth
,Omniauth-LinkedIn
和linkedin
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
答案 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