I looked through the API documentation but couldn't find it. It would be nice to grab that number to see how popular a url is. Engadget uses the twitter share button on articles if you're looking for an example. I'm attempting to do this through javascript. Any help is appreciated.
To find tweets containing an url you have to pass the parameter q="url:stackoverflow.com" . Unfortunately you must have an access token to do this call. More info how to use Twitters search operators can be found at https://developer.twitter.com/en/docs/tweets/search/guides/standard-operators.
TwitCount. @twitcountapp. Unofficial share counts calculator that counts the number of times a URL was shared on Twitter - Not affiliated with Twitter.
Post the Tweet. Open your preferred mobile app, or begin a new text message. Type or paste the URL into your Tweet. Links will be adjusted with Twitter's link shortener wherever you post them.
You can use the following API endpoint,
http://cdn.api.twitter.com/1/urls/count.json?url=http://stackoverflow.com
Note that the http://urls.api.twitter.com/
endpoint is not public.)
The endpoint will return a JSON string similar to,
{"count":27438,"url":"http:\/\/stackoverflow.com\/"}
On the client, if you are making a request to get the URL share count for your own domain (the one the script is running from), then an AJAX request will work (e.g. jQuery.getJSON
). Otherwise, issue a JSONP request by appending callback=?
:
jQuery.getJSON('https://cdn.api.twitter.com/1/urls/count.json?url=http://stackoverflow.com/&callback=?', function (data) { jQuery('#so-url-shares').text(data.count); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="so-url-shares">Calculating...</div>
Update:
As of 21st November 2015, this way of getting twitter share count, does not work anymore. Read more at: https://blog.twitter.com/2015/hard-decisions-for-a-sustainable-platform
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With