Get the number of facebook *shares* of a specific URL
Asked Answered
P

3

21

I've found some discrepancies in the graph api and was wondering if anybody has been able to work around them.

https://graph.facebook.com/?id=http://www.imdb.com/title/tt0117500/ outputs a "likes" number together with all of the open graph info provided by imdb, associated to its fb:app_id. https://graph.facebook.com/?id=http://www.google.com however, outputs the "shares" number, as google doesn't provide an fb:app_id or fb:admins.

My problem is that I need the "shares" number for the first URL, as it corresponds with the number exposed in its like button (likes + comments, etc.)

Is there any way to reliably get this "shares" number for any URL?

Pedant answered 27/2, 2012 at 11:28 Comment(0)
G
57

This API is no longer available. The answer below is no longer valid.


I could get stats of a page (say http://techcrunch.com) with just a GET request to API. Just place this GET request http://api.facebook.com/restserver.php?method=links.getStats&urls=[YOUR_URL] and get the stats.

like http://api.facebook.com/restserver.php?method=links.getStats&urls=http://techcrunch.com/ returns

<links_getStats_response xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
    <link_stat>
        <url>http://techcrunch.com/</url>
        <normalized_url>http://www.techcrunch.com/</normalized_url>
        <share_count>6244</share_count>
        <like_count>1513</like_count>
        <comment_count>1391</comment_count>
        <total_count>9148</total_count>
        <click_count>4007</click_count>
        <comments_fbid>433841427570</comments_fbid>
        <commentsbox_count>4</commentsbox_count>
    </link_stat>
</links_getStats_response>

Hope this helps.


Also,

If you want that response as a JSON, just append &format=json to request URL – Dexter
(from the comment. Thanks Dexter!)

Goulette answered 1/3, 2012 at 7:43 Comment(3)
If you want that response as a JSON, just append &format=json to request URLAindrea
This API is no longer available.Claiborne
As its no longer works this is no longer valid, please provide a valid solution for 2017Troll
U
6

You need to use Facebooks' FQL with table link_stat. Use something similar to this

SELECT
url, normalized_url,
share_count, like_count, comment_count, total_count,
commentsbox_count, comments_fbid, click_count
FROM link_stat
WHERE url="http://www.imdb.com/title/tt0117500/"

This is the result for that query (in XML format, you can of course get it in JSON)

<?xml version="1.0" encoding="UTF-8"?>
<fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
  <link_stat>
    <url>http://www.imdb.com/title/tt0117500/</url>
    <normalized_url>http://www.imdb.com/title/tt0117500/</normalized_url>
    <share_count>6233</share_count>
    <like_count>9500</like_count>
    <comment_count>2179</comment_count>
    <total_count>17912</total_count>
    <commentsbox_count>6</commentsbox_count>
    <comments_fbid>380728101301</comments_fbid>
    <click_count>164</click_count>
  </link_stat>
</fql_query_response>

The total_count (17912) is the number you are looking for.

Unwearied answered 1/3, 2012 at 6:37 Comment(1)
"As of August 8 2016, FQL will no longer be available and cannot be queried". - developers.facebook.com/docs/technical-guides/fqlClaiborne
C
0

The previous API options from Facebook are no longer available. Assuming you'd like to do this programmatically, Facebook does not currently provide a way of doing so (as far as I can tell).

You could potentially scrape the source of your Facebook like button example, but that seems prone to breaking, especially given the history of their previous actions.

One third-party option I found was SharedCount, which has an API available. It requires registering a free account, but a making a GET request to this endpoint will result in the following sample response:

{"StumbleUpon":1,"Pinterest":9,"LinkedIn":3744,"Facebook":{"total_count":
168,"comment_count":53,"reaction_count":14,"share_count":
101, "comment_plugin_count":0},"GooglePlusOne":189}

From there, you can parse out the Facebook total_count value, which should correspond with what you'd see next to an embedded Facebook share button.

Of note, I had to remove the trailing forward slash from your sample URL in order for the SharedCount value returned from their API to match the count in the button example, so you may want to play around to ensure it's working accurately for your use case.

Cleopatracleopatre answered 4/1, 2020 at 23:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.