React Native open Facebook page

安稳与你 提交于 2019-12-10 15:56:17

问题


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.


回答1:


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');



回答2:


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.




回答3:


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.




回答4:


Update - May 2019

// open via app

fb://facewebmodal/f?href=PAGE_NAME



回答5:


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/



来源:https://stackoverflow.com/questions/46616348/react-native-open-facebook-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!