Skip to content

Instantly share code, notes, and snippets.

@nilsandrey
Last active May 2, 2024 02:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilsandrey/3152f585dfa67b534cd8402a3e9525ba to your computer and use it in GitHub Desktop.
Save nilsandrey/3152f585dfa67b534cd8402a3e9525ba to your computer and use it in GitHub Desktop.
How many times a web link has been shared on Twitter
// <https://www.barattalo.it/coding/how-many-times-a-web-link-has-been-shared-on-twitter/>
function readTwitterShares($url) {
$s = file_get_contents("http://urls.api.twitter.com/1/urls/count.json".
"?callback=?&url=".urlencode($url));
preg_match("#(\"count\"):([0-9]*)#",$s,$ar);
return isset($ar[2]) ? $ar[2] : 0;
}
echo readTwitterShares("https://www.nationalgeographic.com/science/article/a-psychedelic-surprise-may-be-thriving-in-your-local-garden");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment