2016-10-24 32 views

回答

1

如果訪問令牌不再有效,你可以拯救Instagram::BadRequest例外:

@token = 'xXxXxX...' 
@client = Instagram.client(access_token: @token) 

begin 
    user = @client.user 
    # YOUR LOGIC HERE 
rescue Instagram::BadRequest => e 
    if e.message =~ /access_token provided is invalid/ 
    # ACCESS TOKEN IS NO LONGER VALID 
    # DO SOMETHING E.G. SEND THE USER AN EMAIL 
    else 
    # IT RETURNED 400 FOR ANOTHER REASON 
    end 
end