Getting Twitter Share Count using Spring Java Rest Service



As part of current caching system, we are trying to fetch twitter share count for our site url using “” . We call this API from Spring Java Rest Controller and store the count into our system to show it for next few minutes. This Api works fine for few attempts for the same url. But many time this is throwing timeout exception even after retrial.

We tried to run curl command on above API for same url and we see the same behavior. Do we know, why it is happening. Does twitter blocks server Ip address if many requests comes from same server. Is it the right API to get count for a url or do we need to use different API.

Any help in this regard will be great.


Retrieving URL Tweet counts on the backend

That endpoint isn’t supported and will disappear soon: Retrieving URL Tweet counts on the backend


Thanks. Do you know, what is the best to get share count from java services? Please suggest.


Per the announcement about changes to the share buttons:

The Twitter REST API’s search endpoints are the best way to gather ad-hoc information about a URL shared on Twitter; full-archive search counts are available from Gnip.

Retrieving URL Tweet counts on the backend

Thanks Andy, It looks like none of the API provides direct count results like “”. I tried using oAuth search API But it returns whole search object , which has so many status_count. So not sure how to approach for this.

It will be great, if you can directly point me to the API url which provides count for a url, similar to “


There is no API endpoint that provides this information in a single call.


Thanks Andy, So it means, To get the count we need to write custom logic based on search API. As I mentioned I tried search APIs too. But none of these API give response with all the tweet objects. So any other API which at least can provide all the tweets for a site url. I am sure, this must be pretty much common requirement. Thanks for help.


As stated in the announcement about the change, you can either use the public search API, or the Gnip APIs. Those are the options available.