2011-09-01 28 views
7

tôi đã tự hỏi làm thế nào tôi có thể bắt được một ngoại lệ koala oauth (ví dụ như thiết lập lại mật khẩu người dùng).Cách bắt Koala :: Facebook :: APIError OAuthException hoặc thiết lập lại mật khẩu người dùng

ngay bây giờ đây là những gì tôi có/sử dụng cho đến nay:

rescue_from Koala::Facebook::APIError do 
    # redirect to fb auth dialog 
end 

nhưng điều này bắt tất cả các lỗi .. làm thế nào tôi có thể làm điều đó với chỉ oauth hoặc chỉ đặt lại mật khẩu?

EDIT:

phát hiện ra một giải pháp rõ ràng hơn đối với các vấn đề:

rescue_from Koala::Facebook::APIError do |exception| 
    if exception.fb_error_type == 190 
    # password reset - redirect to auth dialog 
    else 
    raise "Facebook Error: #{exception.fb_error_type}" 
    end 
end 

cảm ơn trước oliver

Trả lời

2

tôi sẽ cho bạn thấy một số mã tôi có, và làm thế nào tôi quản lý để bắt và cứu hộ từ trường hợp ngoại lệ Koala:

def post_message_facebook_wall(message) 
    unless self.token.nil? 
     begin 
     facebook_graph = Koala::Facebook::GraphAPI.new(self.token) 
     object_from_koala = facebook_graph.put_wall_post(message) 
     rescue Koala::Facebook::APIError => exc 
     logger.error("Problems posting to Facebook Wall..."+self.inspect+" "+exc.message) 
     end 
    end 
end 

Th là rescue Koala::Facebook::APIError => exc nên thực hiện thủ thuật.

Các vấn đề liên quan