I’m using Koala for Facebook Graph API calls and am using a block for all of my users to collect new data; however, one of my users has changed their password, so now I’m getting a Koala::Facebook::APIError: OAuthException error in my block and it’s not running any of the block after the exception. How do I detect the exception and skip that user?
User.all.each do |g|
@graph = Koala::Facebook::API.new(Service.find_by_user_id(g.id).access_token)
@friends = @graph.get_connections("me", "friends")
etc...
end
I’ve attempted three potential solutions, but don’t know how to implement them correctly or if there’s a better way. When I use rescue it just completes the entire block without doing anything. Eventually I will need to get a new access token, but for now I just want to be able to skip them and continue the block.
rescue_from Koala::Facebook::APIError
rescue Koala::Facebook::APIError => e
if Koala::Facebook::API.new(Service.find_by_user_id(g.id).access_token) == Koala::Facebook::APIError
return
end
You need to get new access_token every-time you call FB Graph API.
From your code it looks like you are using same access token that you got for the first time when user connected to your site. It is not right.