14

I've been trying to open Facebook page using React Native Linking API. It doesn't work for me. I do have Facebook app installed. Here is what I tried:

Linking.openURL('fb://page/<page_name>');
Linking.openURL('fb://profile/<profile_name>');
Linking.openURL('http://facebook.com/<page_name>');

I also tried to use Communications library: Communications.web(url). None works for Facebook and Instagram. However it works like a charm for Google Maps, Apple Maps, Twitter and other big guys.

I was wondering if I was doing something wrong or maybe we should send some Android articles to those people from Facebook on how to properly implement deep linking in their apps? They clearly don't know what they are doing.

Andrei
  • 42,814
  • 35
  • 154
  • 218

7 Answers7

20

Ok, found one way to open Facebook:

Linking.openURL('fb://page/PAGE_ID');
Linking.openURL('http://instagram.com/_u/USER_NAME');
Linking.openURL('http://instagram.com/_p/PICTURE');
Andrei
  • 42,814
  • 35
  • 154
  • 218
  • Can you tell me the deep link for posting news feed with text on Facebook (Like: fb:// xxxx/xxxxxx/xxx) If possible then same for Instagram? – Utkarsh May 02 '20 at 09:38
  • Hi, if the facebook app i not installed then its not working for some reason. – kd12345 Nov 21 '22 at 08:35
8

In general, you should check Linking.canOpenURL() for iOS before trying to open them.

Also, make sure you add your protocols as an array in info.plist as:

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>fb</string>
</array>

You can also do this in your Xcode project in info.plist.

AMB
  • 221
  • 3
  • 8
6

I'm having the same issue, but not able to solve it. I have multiple social networking buttons with the onpress action of onPress= {()=> Linking.openURL("https://www.SOME_SOCIAL.NETWORK")} My buttons linking to Twitter, Instagram, and SnapChat all open the app if installed or a web page in Safari if the app is not installed. The only outlier is Facebook. Given an onpress action such as onPress= {()=> Linking.openURL("https://www.facebook.com/")} the link will always open in Safari even if the app is installed.

Because of this odd behavior I'm handling my onpress action for the Facebook link like this:

```

  Linking.canOpenURL("fb://profile/XXXXXX").then(supported => {
    if (supported) {
      return Linking.openURL("fb://profile/XXXXXX");
    } else {
      return Linking.openURL("https://www.facebook.com/");
    }
  })

```

The above code doesn't work as intended, but nothing else seems to.

okTalk
  • 1,112
  • 1
  • 10
  • 11
  • It wasn't until I added this supported check, that React Native threw a warning that I needed to add "fb" to LSApplicationQueriesSchemes as described in @AMB answer below – SeanMC Aug 20 '21 at 02:28
1

Update - May 2019

// open via app

fb://facewebmodal/f?href=PAGE_NAME
matt93
  • 368
  • 4
  • 15
1

According to the docs https://reactnative.dev/docs/linking#canopenurl. Promise can be rejected for android. This is my approach to handle this for iOS and android

import { Linking } from 'react-native';

const handleOpenLink = async (url) => {
  try {
    await Linking.openURL(url);
  } catch {
    throw new Error('URI cant open:' + url);
  }
};
Slava Vasylenko
  • 838
  • 1
  • 9
  • 14
1

Worked for me using these :

    facebookApp: 'fb://page/318948148343',
    facebookAppIos: 'fb://page/?id=318948148343',
    instagramApp: 'instagram://user?username=stackAnswer',
    youtubeApp: 'vnd.youtube://channel/UCPHssSTfq-K823dDJnvXqgw',
    linkedInApp: 'linkedin://company/google',
  • Notice the difference between both facebook links (for iOS you must specify the id as param)

Also, don't forget to add equivalent attributes in Info.plist for apps to be allowed, as:

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>facebook</string>
        <string>fb</string>
        <string>instagram</string>
        <string>vnd.youtube</string>
        <string>linkedin</string>
    </array>
Ayoub EL ABOUSSI
  • 636
  • 6
  • 13
0

Nothing here worked for me, but with some random tryings, i found this solution working :

Linking.openURL('fb://page/<ID-PAGE>');

And if you are looking for your pageid, here's a little tutorial : https://roadtoblogging.com/get-facebook-page-id/

codeinu
  • 21
  • 4