huacnlee / social-share-button

Helper for add social share feature in your Rails app. Twitter, Facebook, Weibo, Douban ...
MIT License
582 stars 309 forks source link

Facebook sharing error #157

Closed HusseinReda closed 6 years ago

HusseinReda commented 6 years ago

When I'm using facebook sharing, the following error appears:

screen shot 2017-12-29 at 8 37 13 pm

I'm not pretty sure whether this is an issue in facebook sharer itself or the integration in the gem, if anyone is aware with this issue please advise.

nicolasconnault commented 6 years ago

I'm having the same issue. The reason is that the URL is encoded, which is not supported by Facebook's sharer.php script. The solution would be to replace line 43 of social-share-button.js with SocialShareButton.openUrl("http://www.facebook.com/sharer.php?u=" + decodeURIComponent(url), popup);

However, as I'm not in a position to modify the gem files, I'm trying to find a way to decode the URI before it gets passed to this function.

nicolasconnault commented 6 years ago

Actually scrap that! The reason it's not working is because Facebook tries to load the provided URI, so if you're using an inaccessible page (like http://localhost), it fails. This should work fine on a production server (trying now, will update to let you know!).

Yes, I can confirm, it's just a localhost issue :)

bfeller commented 6 years ago

I'm having this issue in production as well.

atd commented 6 years ago

In our case, this is because the default quote or desc parameter is set to ' ' (see https://github.com/huacnlee/social-share-button/blob/master/app/assets/javascripts/social-share-button.coffee#L17)

This is making the encoded url send to fb to end in quote=%20, which fb doesn't like. Try to delete the last %20 and it should work

@huacnlee what about a PR fixing this?