1

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.

Trey
  • 5,480
  • 4
  • 23
  • 30
  • That post, and it's answer, relate to opening a native Facebook page from the Facebook browser. I'm trying to open a Facebook page in the Facebook app, using a link in mobile safari – Trey Oct 04 '22 at 04:10

2 Answers2

3

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"
}
Troy
  • 690
  • 1
  • 7
  • 25
  • This is what I've been missing, using the new pages experience I hadn't been able to find the page id, thanks for that. This is the method I had seen around the web, thanks for helping with the missing piece! – Trey Oct 12 '22 at 12:52
1

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.

cactusboat
  • 778
  • 2
  • 7
  • 15
  • 1
    This page was set up using the new pages experience, I haven't been able to find the page id, in my case the page name shows up at the end of the url, but the method was correct, thank you – Trey Oct 12 '22 at 12:51