Check if twitter username exists

前端 未结 9 1748
旧巷少年郎
旧巷少年郎 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 10:47

    As API v1 is no longer available, here is another way to check if a twitter account exists. The page headers of a non existing account contain 404 (page not found).

    function twitterAccountExists($username){
        $headers = get_headers("https://twitter.com/".$username);
        if(strpos($headers[0], '404') !== false ) {
            return false;
        } else {
            return true;
        }
    }
    

提交回复
热议问题