Reputation: 44640
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.
Upvotes: 14
Views: 23565
Reputation: 704
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',
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>
Upvotes: 1
Reputation: 1014
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);
}
};
Upvotes: 1
Reputation: 44640
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');
Upvotes: 20
Reputation: 21
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/
Upvotes: 0
Reputation: 366
Update - May 2019
// open via app
fb://facewebmodal/f?href=PAGE_NAME
Upvotes: 1
Reputation: 1212
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.
Upvotes: 7
Reputation: 221
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
.
Upvotes: 8