Check if twitter username exists

前端 未结 9 1617
旧巷少年郎
旧巷少年郎 2021-02-05 10:28

Is there a way to check if a twitter username exists? Without being authenticated with OAuth or the twitter basic authentication?

9条回答
  •  一个人的身影
    2021-02-05 11:08

    Using Ruby, you could install the twitter gem and then define the following method:

    require 'twitter'
    
    def user_exists?(user)
      Twitter.user(user)
      true
    rescue Twitter::NotFound
      false
    end
    

    Then, simply pass in a Twitter user name or id to your method, like so:

    user_exists?("sferik") #=> true
    user_exists?(7505382) #=> true
    

提交回复
热议问题