4

我正在尝试通过 react-native-fbsdk 包在 React Native 中将图像分享给 Facebook。

我有以下内容,几乎完全是从文档中复制的,但我不知道如何格式化imageUrl,我不断收到错误说SharingContent is invalid.

我在这里做错了什么?

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

2 回答 2

2

您可以使用 react-native-image- picker https://github.com/marcshilling/react-native-image-picker获取图像的 uri 并使用它创建 SharePhotoContent。

另请注意,您需要安装 facebook 应用程序才能共享图像。

于 2016-06-06T06:07:32.417 回答
-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);
      }
    );
  }
于 2018-02-22T08:29:48.100 回答