Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get the twitter share count for a specific URL?

Tags:

twitter

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.

like image 231
Xavier Avatar asked Jan 23 '11 18:01

Xavier


People also ask

How do I find tweets that contain a URL?

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.

What is TwitCount?

TwitCount. @twitcountapp. Unofficial share counts calculator that counts the number of times a URL was shared on Twitter - Not affiliated with Twitter.

How do I share a URL on 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.


1 Answers

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

like image 178
user799188 Avatar answered Sep 18 '22 17:09

user799188