Comment savoir si un compte Twitter a été suspendu en PHP ?

Réponses rédigées par Antoine
Dernière mise à jour : 2018-08-27 15:46:44
Thèmes : script - php - curl - twitter - webmaster
Question

Comment puis-je savoir si un compte Twitter a été suspendu en PHP ?

Réponse

Vous pouvez utiliser CURL et PHP pour connaitre le statut d'un compte Twitter, à savoir si le compte Twitter est ouvert ou si il a été suspendu.

Si la fonction retourne un code HTTP différent de 200 c'est que le compte Twitter a de grande chance d'avoir été suspendu.

function getStatusTwitter($url)
{
$header = null;
$options = array(
//CURLOPT_PROXY => "127.0.0.1:8080",
//CURLOPT_PROXYUSERPWD => "user:password",
//CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER         => true,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_ENCODING       => "",
CURLOPT_USERAGENT      => "spider",
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_AUTOREFERER    => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT        => 120,
CURLOPT_MAXREDIRS      => 10,
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
if(!curl_errno($ch))
{
$header = curl_getinfo($ch);
}
curl_close($ch);
return $header['http_code'];
}

Voici comment utiliser la fonction:

if(getStatustwitter("LE_COMPTE") !== 200)
{
   echo "le compte est suspendu";
}
else echo "le compte est actif";