与react-native-fbsdk共享图像? [英] Share an image with react-native-fbsdk?

查看:152
本文介绍了与react-native-fbsdk共享图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to share an image to Facebook in React Native through the react-native-fbsdk package.

我有以下几乎完全从文档复制,但我无法弄清楚如何格式化 imageUrl ,我不断收到错误,说 SharingContent无效

I have the following, copied almost completely from the docs, but I can't figure out how to format the imageUrl, I keep getting errors saying the 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);
  }
);


推荐答案

您可以使用反应本机图像选择器 https://github.com/marcshilling/react-native-image-picker 获取图像的uri并使用它创建一个SharePhotoContent。

You can use the react-native-image-picker https://github.com/marcshilling/react-native-image-picker to get the uri of the image and use it create a SharePhotoContent.

另请注意,您需要安装Facebook应用才能分享图片。

Also note that you need to have the facebook app installed in order to share an image.

这篇关于与react-native-fbsdk共享图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆