Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deeplink to Facebook App (using fb: protocol) not working from Facebook in-app browser

I am writing a mobile web page which has both a redirect and two manual backup links (for when the redirect doesn't work) to a Facebook Page.

The link takes the form:

fb://page/[PAGE ID NUMBER]

The redirect and link work in Chrome Mobile and Firefox Mobile but (surprise) they don't work in Facebook Browser which, instead, gives me the error:

Page can't be loaded.

I am perplexed that a link to the Facebook App doesn't work from within the Facebook Browser.

How can I resolve this? Are there any creative solutions or workarounds... or have I missed something obvious?


Additional Info: It looks like the redirect is working in at least one version of the Facebook Browser on the Facebook iOS App. So the issue may be isolated to the Facebook Android App.


UPDATE 1

I've made some progress. I've discovered that Facebook's in-app browser doesn't always (or doesn't ever?) acknowledge / load / execute external script files.

Added: (To find out why not, see Update 8, below...)

In this case the href attributes in the links were being re-populated with fb:// protocol links by an external script after page load.

I have moved the relevant javascript functions from the external script to the bottom of the actual page. I have tested the functions and I can see they are now activating. Although the links still don't work.


UPDATE 2

It struck me that there may be some security mechanism going on behind the scenes which doesn't allow for any javascript-driven re-population of href attributes and that instead of the fb:// protocol links not working, it was maybe the case that the initial, default http://www.facebook.com/ links were never even being replaced and it was those http:// protocol links that weren't working.

So I updated the PHP template, so that the initial default links were the fb:// instead of the http:// links (so nothing in the page delivered to the Facebook in-app browser would need to be updated by any client-side script at all at any point).

Nope. Still not working.


UPDATE 3

I added a plain vanilla link to the bottom of the page, linking to the site's homepage. The link functioned entirely normally.

Later, I pointed the original links to an external domain. They didn't work.

So... I concluded that only http:// protocol links to the same domain would work and that's why the links wouldn't work if they pointed to an external domain or to an fb:// protocol address.

Wrong conclusion.

I pointed the original links at the site's homepage and they still didn't work.


UPDATE 4

In a moment of inspiration, I removed the reference to the external script which I'd set up to customise the links to the OS + browser environment (even though this script reference was being entirely ignored by Facebook, according to the FB Debugging tool.

The links worked.

So the reason why the plain vanilla link I had added earlier had worked, was nothing to do with where it was pointing and simply to do with the fact that at no point had a script tried to access it or update it.

Added: (This isn't the reason. See Update 8, below...)

I pointed the original links at the external domain. They worked.

I pointed the original links at the fb:// protocol. They didn't work.


UPDATE 5

Now that I've got rid of the external script reference, I can point the original protocol links at any http:// protocol address and they work.

Including the http://www.facebook.com web equivalent of the page I am trying to open in the Facebook App.

Let's review that:

The Facebook website is opening in the Facebook in-app browser.

I know, right?


UPDATE 6 [.HTACCESS REDIRECT]

I changed the link destination to /fb-custom-redirect/.

Then I added a line to the mod_rewrite section of my .htaccess file:

RewriteRule ^fb-custom-redirect fb://page/[PAGE ID NUMBER]

Naturally the server didn't understand what I was asking for.


UPDATE 7 [PHP REDIRECT]

I created an index.php for /fb-custom-redirect/ and added the following:

<?php
header('Location: fb://page/[PAGE ID NUMBER]');
?>

Guess what? This works in Firefox Mobile. It also works in Chrome Mobile.

But in the Facebook in-app browser, it returns the same error:

Page can't be loaded.

UPDATE 8

I've only just discovered - and this is not insignificant - that when the Facebook Debugger Tool (https://developers.facebook.com/tools/debug/sharing/) refreshes Facebook's cache of a given page, it only refreshes the .html.

Pressing Scrape Again does not refresh any external resources like .css and .js files.

Instead Facebook continues to refer to its own cached versions of those files, regardless that the .html file cache has just been updated.

The workaround (in PHP, at least) is to append the filepath with a new, randomly generated query string every time the page is loaded:

<link rel="stylesheet" href="/styles/mystyles.css?'.uniqid().'" />

Now the Facebook in-app browser is fetching up-to-date versions of my .css and .js files.

This explains my initial observation in Update 1:

I've made some progress. I've discovered that Facebook's in-app browser doesn't always (or doesn't ever?) acknowledge / load / execute external script files.

I'm going to conclude that the Facebook in-app browser was parsing the external .js file reference every time, but it was repeatedly accessing an old, cached version of that file.


Nevertheless, even after all the hypotheses and experimenting above, I'm still no closer to discovering why fb: protocol deeplinks don't work in the Facebook App's in-app browser.

I give up.

like image 782
Rounin - Glory to UKRAINE Avatar asked Aug 19 '19 11:08

Rounin - Glory to UKRAINE


People also ask

How do I force the Facebook app to use an external browser to view links?

In the Facebook app, tap the three-line menu icon at the top right corner, then scroll down to Settings & Privacy -> Settings. Scroll down to Media. At the very bottom, you should see “Links open externally”. Check this box to enable it.

How do I deep link my Facebook page?

To deep link to a specific page, use fb://page/{page_id} for Android and fb://profile/{page_id} for iOS.


1 Answers

Apple apps are sandboxed. This means they cannot access other apps and execute code. Facebook is running a browsing instance and when you try to call the fb:// protocol, the iPhone is blocking you from doing this to try to create an infinite app loading loop. I.e, you open a page in FB browser and it opens itself in FB browser and it opens itself in FB browser...

like image 163
Goman60 Avatar answered Oct 21 '22 17:10

Goman60