How to get proper twitter share count for a url?

count
php

#1

Hi All,

I am implementing a function to get twitter count for my url in php. When i am trying to get count using

  $json_string = file_get_contents("http://urls.api.twitter.com/1/urls/count.json?url=http://themarketmogul.com/will-uber-ipo-in-2015");
  $json = json_decode($json_string, true);
  echo intval( $json['count'] );

This return 5 count.
when i directly hit this url

http://urls.api.twitter.com/1/urls/count.json?url=http://themarketmogul.com/will-uber-ipo-in-2015

in browser then i get proper count 6. So please help me how i can get absolute count in php


#2

That URL is not a valid public endpoint for the API and will no longer respond after November 20th.

In addition, it also does not accurately reflect the share count - it doesn’t count Retweets, or variations of the URL, etc.

You’ll need to use the Search API to find Tweets that contain the URL, but that will only cover the past 7 days of Tweet content.


#3

Can you please provide me any hint for search API and how i can get share count using seach API.


#4

Docs for the Search API are available - you’ll want to use GET search/tweets and pass in your URL as a parameter on the query, then count the number of results returned (since you won’t get a single count number from the API).


#5

I have tried to use search API for get twitter count. but in search API i can’t add URL Q parameter does not allow URL. Can you please help me to find out solution for get count. I am very upset. Please help


#6

Hi andypiper,

Now i am trying to use this tool(https://dev.twitter.com/rest/tools/console) for test search API like: https://api.twitter.com/1.1/search/tweets.json?q=http%3A%2F%2Fthemarketmogul.com%2Fwill-uber-ipo-in-2015%2F with authentication But still i am not getting count fot url.

Please help its so urgent for me.


#7

There’s a good chance that all the shares are older than 7 days, so the search API isn’t returning any results.


#8

I am not getting count from search API please help me :tired_face:


#9

I am trying to use search API like: https://api.twitter.com/1.1/search/tweets.json?q=http%3A%2F%2Fthemarketmogul.com%2Fwill-uber-ipo-in-2015%2F
But did’t get count its always return data like:

  "statuses":  [],
  "search_metadata":  {
    "completed_in": 0.016,
    "max_id": 653500633182564400,
    "max_id_str": "653500633182564352",
    "query": "http%3A%2F%2Fthemarketmogul.com%2Fwill-uber-ipo-in-2015%2F",
    "refresh_url": "?since_id=653500633182564352&q=http%3A%2F%2Fthemarketmogul.com%2Fwill-uber-ipo-in-2015%2F&include_entities=1",
    "count": 15,
    "since_id": 0,
    "since_id_str": "0"
  }
}

#10

OK.

If I put your query URL into the public Twitter search page search.twitter.com I get no results.

Using it in the API, I also get no results.

Therefore there is a good chance that it has not been shared within the last 7 days (the scope of the Search API), otherwise you would have a result set of statuses containing the URL.

For example, here’s a search I tried containing a different URL, which worked.

twurl "/1.1/search/tweets.json?q=independent.co.uk"

fun fact - searching just for themarketmogul.com does return a number of results. You’d have to check which t.co link in the result set actually resolved to your target URL though, and then count those.


#11

is their any replacement of count API. Please tell me this is very important


#12

Hi,

Today I found out that have same problem. And can’t track shares from this url http://urls.api.twitter.com/1/urls/count.json?url={myURL}. Please can you tell me with what link this was replaced so I can use that proper one ?


How to get the twitter share count for a specific URL?
How to get count tweet share for url?
#13

Per our announcement in September, this has been removed with no direct replacement at the current time. You can either use the search API, or filter on the streaming API for your URL and count the usage.


#14