Come posso ottenere il numero di retweet di una pagina con PHP?

Esiste una soluzione molto semplice in PHP per ottenere il numero di retweet da Twitter di una pagina.

La soluzione รจ la seguente:


function get_twitter_shares( $url ) {
	$shares = '0';
	if( filter_var( $url, FILTER_VALIDATE_URL ) ) {
		$base_url = 'http://urls.api.twitter.com/1/urls/count.json?url=';
		$twitter_url = $base_url . $url;
		$json_str = file_get_contents( $twitter_url );
		$json = json_decode( $json_str, true );
		$shares = $json['count'];	
	}
	
	return $shares;
}

Torna su