Sharing content on Facebook is not working using FB.ui in for mobile devices?

268 Views Asked by At

I have added the following code which is working great on the Web but not on mobile devices the click event does not seem to be triggering.

    var FacebookShare = function() {
        this.method = 'feed';
        this.name = 'A Name';
        this.hashtag = '#YourHashtag';
    };

    $('#facebook-share').click((event) => {
        let options = new FacebookShare();
        options.quote = $(event.currentTarget.parentElement).find('h5').html() 
        facebookshare(event, options)
    });

    function facebookshare(event, options) {
    event.preventDefault()

    if(typeof(mobileApp) !== 'undefined'){
        options.display = "touch"; //also tried iframe, popup
        FB.ui(options,
        function() {
            console.log('shared');
            })
        }
    } 
1

There are 1 best solutions below

0
user1683987 On

I was able to find a workaround to this issue by overloading the following query string with a quote - which is the text you want to quote and an image (url). The only down fall was that I could not add a hashtag to my post but all in all it worked!

        var u = encodeURI(options.picture);
        var q = encodeURI(options.quote);
        window.location.href = "https://www.facebook.com/sharer/sharer.php?u=" + u + `&quote=${q}&display=popup&ref=plugin&src=like&kid_directed_site=0&app_id=YOUR_APP_ID`