Home > Software design >  Can not open facebook page in the app from a link in iOS browser
Can not open facebook page in the app from a link in iOS browser

Time:10-12

I'm trying to open the facebook app to a certain page with an NFC or QR Code. This works perfectly on the Android, but on iOS I can not for the life of me get the link to behave properly. My code as it stands:

EDIT: The intention is to direct traffic through a page I control for analytics, and open a specific page in the Facebook app. I can open the mobile Facebook page IN safari, and I can open the Facebook app to the correct pager on Android. I have not been able to successfully use a url scheme to create a link in safari that opens Facebook to the business page.

var userAgent = navigator.userAgent || navigator.vendor || window.opera;
var isAndroid = (/android/i.test(userAgent));
var isIOS = (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream);
var isDesktop = !isAndroid && !isIOS;
var pageName = 'stubque.springfield';
var page_url = 'https://www.facebook.com/' pageName;
var isFocused = true;

setTimeout(() => {
    if(isDesktop) this.location=page_url;
    if(isAndroid) fburl = "fb://facewebmodal/f?href=" encodeURI(page_url);
    if(isIOS){
        //opens facebook, but not page
        fburl = "fb://faceweb/f?href=" encodeURI(page_url);
        fburl = "fb://" pageName;
        fburl = "fb://page/" pageName;
        fburl = "fb://facewebmodal/f?href=" encodeURI(page_url);
        fburl = "fb://profile/" pageName;

        //opens facebook but stuck on loading screen
        fburl = "fb://page?id=" pageName;
    }
    addEventListener('blur', (event) => { isFocused = false; });
    setTimeout(() => {
        if(isFocused) this.location = page_url;
    }, 100);
    this.location=fburl;
}, 1800);

Has anyone had any luck using URL Schemes to open a page in-app on facebook?

EDIT 2: I realized that facebook now assigns a QR code to all pages automatically, scanning the QR code on android opens the page as expected, however on my (admittedly old) iPhone, it sends me to an error page that says "Sorry, this feature isn't available right now". I have someone who has been testing on a new iPhone for me, but if they end up with the same result, I'm concerned that it may mean deep linking is completely broken for Facebook on iOS.

CodePudding user response:

The Facebook iOS app URI scheme will only recognize the numeric id of your page (not the named id "stubque.springfield").

Your page id is 100086393472203.

I obtained the numeric id for your page by running this on the command line:

curl -skA "Mozilla/5.0" https://www.facebook.com/stubque.springfield/ | grep -oE "fb://[^\"] "
# fb://profile/100086393472203

Command is taken from: https://stackoverflow.com/a/33363610

So you should update the iOS part of your code to this:

if(isIOS){
    //opens facebook app to the stubque.springfield page
    fburl = "fb://profile/100086393472203"
}

CodePudding user response:

I have found a solution that works for me. I'm not sure if it will work for everyone, but it's worth a shot.

I was able to get the facebook app to open to the correct page by using the following URL: fb://profile/<page_id>

I was able to get the page_id by going to the page in the facebook app, and clicking the three dots in the top right corner. This will open a menu, and the page_id is the number at the end of the URL.

  • Related