Sharrre icon indicating copy to clipboard operation
Sharrre copied to clipboard

REST API is gone, facebook share count is not working now

Open Coyoter opened this issue 8 years ago • 21 comments

Aug 18, the FB REST API is gone.

There are any solution to fix my share count?

Coyoter avatar Aug 19 '16 08:08 Coyoter

Can confirm also, Facebook numbers are all zero now. Even in their demos.

neotropic2023 avatar Aug 19 '16 19:08 neotropic2023

Could be solved by using graph.facebook.com/{url} instead of FQL

tarqd avatar Aug 20 '16 01:08 tarqd

Same for us, I'll try the graph api mentioned above

sphism avatar Aug 21 '16 23:08 sphism

Got the fb share counts working again... two bits of code need altering: Weirdly you have to switch back to a previous version of the facebook api (no idea why)

/* Json URL to get count number
  ================================================== */
  urlJson = {
    googlePlus: "",

    //new FQL method by Sire
    //facebook: "https://graph.facebook.com/fql?q=SELECT%20url,%20normalized_url,%20share_count,%20like_count,%20comment_count,%20total_count,commentsbox_count,%20comments_fbid,%20click_count%20FROM%20link_stat%20WHERE%20url=%27{url}%27&callback=?",
    //old method
    facebook: "http://graph.facebook.com/?id={url}&callback=?",
    //facebook : "http://api.ak.facebook.com/restserver.php?v=1.0&method=links.getStats&urls={url}&format=json"

Then the returned format is different so you have to change that too:

//get the FB total count (shares, likes and more)
        //else if(json.data && json.data.length > 0 && typeof json.data[0].total_count !== "undefined"){ //Facebook total count
        //  count += parseInt(json.data[0].total_count, 10);
        //}

        // Hacked: matt: FB api no longer returns share count, switching api's
        // returns data in this format now.
        else if(json.share && json.share && typeof json.share.share_count !== "undefined"){ //Facebook total count
          count += parseInt(json.share.share_count, 10);
        }
        // End hacked: matt

sphism avatar Aug 22 '16 06:08 sphism

Same problem here and your hack worked for me @sphism. Thank you!

ablunier avatar Aug 22 '16 08:08 ablunier

See Pull Request #296 - I've implemented @sphism 's changes... with a minor tweak - should be on HTTPS.

njt1982 avatar Aug 22 '16 09:08 njt1982

I implemented the hack from @sphism and my counts are still not working. GitHub is saying the code was last updated March 3. I seem to be missing something.

I found this article published last week: http://www.inc.com/james-parsons/the-era-of-the-share-count-is-coming-to-an-end.html that says FB Shared counts are no longer available...

martinfritch avatar Aug 22 '16 18:08 martinfritch

@martinfritch Have a play with the facebook graph explorer, that's how i figured out how to get ours working yesterday. https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=%3Fid%3Dhttp%253A%252F%252Fwww.imdb.com%252Ftitle%252Ftt2015381%252F&version=v2.7

Also try the code from the pull request @njt1982 made: https://github.com/Julienh/Sharrre/pull/296

sphism avatar Aug 22 '16 21:08 sphism

@martinfritch did you use http or https for the graph facebook URL? http did not work on our project as the project is hosted on https. Chrome blocked the request.

That graph URL does (currently) work, but I have no idea if/when it'll be retired. It might just be that the person that wrote the blog didn't look around for new URLs..

This definitely works: https://graph.facebook.com/?id=https://github.com/&callback=test

njt1982 avatar Aug 22 '16 21:08 njt1982

Glad to find this fix. Thanks @sphism this worked for me.

Ewster avatar Aug 23 '16 06:08 Ewster

@sphism 's fix didn't work for me -- we're still getting 0s everywhere. Anyone know of any alternatives to sharrre that can accomplish the same thing?

aandrewjoyce avatar Aug 23 '16 19:08 aandrewjoyce

Just an update: I got @sphism 's fix to work. Not sure what exactly I did, or what changed, but after working on it for several hours and trying different variations, I got a valid response back and now the counts are working fine!

martinfritch avatar Aug 23 '16 19:08 martinfritch

@martinfritch do you use any kind of version control so you can get a diff to see what you changed?

@aandrewjoyce did you change it from http to https? Do you get any errors in the console or network tab?

This patch does work, so if it doesn't work for you it would be good to know why.

njt1982 avatar Aug 23 '16 21:08 njt1982

@martinfritch glad you got it sorted.

@aandrewjoyce Not sure what to say. Have you tried using the graph api explorer https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=%3Fid%3Dhttp%253A%252F%252Fwww.imdb.com%252Ftitle%252Ftt2015381%252F&version=v2.7

I made sure i was getting results in there first, then figured out how to get it working on our site.

There are loads of different version of the api, I wonder if the one you are using returns the data in a slightly different format???? If you look in the jquery.sharrre.js file for the Plugin.prototype.getSocialJson method, you can uncomment this line

//console.log(json); //debug

Then you see all the returned JSON from each of the social sites. The facebook fql api used to return the share count as:

json.data[0].total_count

The graph api i just switched to returns it as:

json.share.share_count

It might be that the version of the api you are connecting to returns it slightly differently??? I'm not sure, I don't know much about the different fb api's.

If you use that graph api explorer i liked to above then you might be able to figure it out

sphism avatar Aug 23 '16 22:08 sphism

The code I'm using is exactly what @sphism posted. However, the query isn't working again this morning. I'm getting the following response back from FB:

   "error": {
      "message": "(#4) Application request limit reached",
      "type": "OAuthException",
      "is_transient": true,
      "code": 4,
      "fbtrace_id": "DzW6CEr+WDZ"
   }

I bet this is why my first attempt appeared to be not working.

martinfritch avatar Aug 24 '16 12:08 martinfritch

ahhh interesting! Never considered that Facebook would implement API limits...

njt1982 avatar Aug 24 '16 13:08 njt1982

Check my website's share counter, it's working now:

http://www.hungry.tw/2016/08/ShanHaiGo.html

How I fixed that :

First Step. Change the "Json url to get count number" in your sharer.js, ex

/* Json URL to get count number ================================================== */ urlJson = { googlePlus: "", facebook: "https://graph.facebook.com/v2.7/?access_token=PUTYOURTOKENHERE&id={url}&callback=?", //facebook : "http://api.ak.facebook.com/restserver.php?v=1.0&method=links.getStats&urls={url}&format=json"

Second Step. Add one line code at : //console.log('name : ' + name + ' - url : '+url); //debug

ex.

} else if (typeof json[0] !== "undefined") { //Stumbleupon } else if (typeof json.share !== "undefined") { count += parseInt(json.share.share_count, 10);

you can use cmd(ctrl)+(F) to find "//Stumbleupon", and you will find that.

the counter works fine now!!! of course, you need an Facebook app token first.

You can find your token here if you already have an Facebook app:

https://developers.facebook.com/tools/accesstoken/

Enjoy your counter now : )

warning: An app token have limit of request. I suggest every people using the personal token for themself, and do not using other people's token. It's easy to reach the limit.

To create a Facebook app is easy and free. You do not need any Code skill.

Yu-Ci

Coyoter avatar Aug 24 '16 17:08 Coyoter

I'm confused... doesn't the USER token have a time limit (2 mos) while the APP token does not? And I'm guessing the app token should not be used here because it's client side, per the facebook documentation?

MeDroogie avatar Aug 27 '16 00:08 MeDroogie

All token have limit, and you can check my.site its works.

Coyoter avatar Aug 27 '16 02:08 Coyoter

Thanks @nikksan!

(there's a bug in your Markdown by the way - your link is not clickable)

https://fragrances.bg/blog/wp-content/themes/hueman/js/jquery.sharrre.min.js?ver=4.2.2

Patabugen avatar Sep 29 '16 15:09 Patabugen

@nikksan your fix sets 41 facebook likes to all posts.

AlxMedia avatar Nov 01 '16 18:11 AlxMedia