Julienh / Sharrre

Make your sharing widget! Sharrre is a jQuery plugin that allows you to create nice widgets sharing for Facebook, Twitter, Google Plus (with PHP script) and more.
sharrre.com
MIT License
1.04k stars 413 forks source link

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

Open Coyoter opened 7 years ago

Coyoter commented 7 years ago

Aug 18, the FB REST API is gone.

There are any solution to fix my share count?

neotropic2023 commented 7 years ago

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

tarqd commented 7 years ago

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

sphism commented 7 years ago

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

sphism commented 7 years ago

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
ablunier commented 7 years ago

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

njt1982 commented 7 years ago

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

martinfritch commented 7 years ago

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...

sphism commented 7 years ago

@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

njt1982 commented 7 years ago

@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

Ewster commented 7 years ago

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

aandrewjoyce commented 7 years ago

@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?

martinfritch commented 7 years ago

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!

njt1982 commented 7 years ago

@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.

sphism commented 7 years ago

@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

martinfritch commented 7 years ago

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.

njt1982 commented 7 years ago

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

Coyoter commented 7 years ago

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

MeDroogie commented 7 years ago

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?

Coyoter commented 7 years ago

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

Patabugen commented 7 years ago

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

AlxMedia commented 7 years ago

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