Separate image with reaction-native-fbsdk?

I am trying to share a Facebook image in React Native through the react-native-fbsdk package.

I have the following, copied almost entirely from the documents, but I can’t figure out how to format it imageUrl, I keep getting errors saying SharingContent is invalid.

What am I doing wrong here?

const sharePhotoContent = {
  contentType: 'photo',
  photos: [
    {
      imageUrl: "./local/image/path.png",
      userGenerated: false,
      caption: "Hello World"
    }
  ]
};

ShareDialog.canShow(sharePhotoContent).then(
  function(canShow) {
    if (canShow) {
      return ShareDialog.show(sharePhotoContent);
    }
  }
).then(
  function(result) {
    if (result.isCancelled) {
      AlertIOS.alert('Share cancelled');
    } else {
      AlertIOS.alert('Share success with postId: ' + result.postId);
    }
  },
  function(error) {
    AlertIOS.alert('Share fail with error: ' + error);
  }
);
+4
source share
2 answers

To get the uri of the image and use it create SharePhotoContent, you can use the utility change-native-image-picker https://github.com/marcshilling/react-native-image-picker .

, facebook.

+1
This is working fine for me 

  shareLinkWithShareDialog() {

let shareLinkContent = {

contentType: 'link',

contentUrl: 'https://www.facebook.com/images/fb_icon_325x325.png',

contentDescription: 'Facebook sharing is easy!'
      }

 ShareDialog.canShow(shareLinkContent).then((canShow) => {

if (canShow) return ShareDialog.show(shareLinkContent);

 }

).then((result) => {

 if (result.isCancelled) {

  alert('Share cancelled');

 } else {

   alert('Share success with postId: ' + result.postId);

   }

  },

  function(error) {

  alert('Share fail with error: ' + error);
      }
    );
  }
0

All Articles