【问题标题】:Share an image with react-native-fbsdk?与 react-native-fbsdk 共享图像?
【发布时间】:2016-08-31 20:54:24
【问题描述】:

我正在尝试通过 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);
  }
);

【问题讨论】:

  • 我知道已经有一段时间了,但我想知道你是否找到了一种方法来做到这一点(在你的项目中为 .png 构建一个 url 并与 react-native-fbsdk 共享它,那是)?谢谢
  • 没有。我从来没有弄明白。
  • 感谢您回复我,是的,您会认为 Facebook 会让其中的一些内容更加透明,因为 RN 是他们的宝贝。哦,好吧

标签: facebook react-native react-native-fbsdk


【解决方案1】:

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

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

【讨论】:

  • 为什么我的 fbsdk 中没有点击 facebook 登录按钮?
  • @SusylGhimire 我们应该为此打开一个新的 stackoverflow 问题吗?
【解决方案2】:
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);
      }
    );
  }

【讨论】:

  • 关于分享图片而不是链接的问题
猜你喜欢
  • 1970-01-01
  • 2018-01-18
  • 2017-01-31
  • 2017-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多