【问题标题】:Share post on LinkedIn with React Native使用 React Native 在 LinkedIn 上分享帖子
【发布时间】:2020-06-01 22:41:30
【问题描述】:

我有一个内置 react-native 的应用,我需要在 LinkedIn 上分享包含预定义内容的帖子。

我使用“react-native-share”在 LinkedIn 上分享内容,但它不起作用。我怎样才能做到这一点?

提前致谢。

【问题讨论】:

  • 请添加您的代码

标签: react-native linkedin


【解决方案1】:

LinkedIn 只支持传递给它的一个参数,那就是url 参数。它看起来像这样......

https://www.linkedin.com/sharing/share-offsite/?url={url}

来源:Official LinkedIn Sharing Documentation

以下参数将不起作用summarytitlesource 等。除了url 之外的任何参数。

要分享到 LinkedIn,只需创建一个指向上述格式化 URL 的 <a href> 元素,并确保对您的 {url} 进行 URL 编码。

不过,根据接受的答案,您可能想分享titlesummary。你不能使用GET-data 来做到这一点,但是你可以使用og: 标签来做到这一点。

  • <meta property='og:title' content='Title of the article"/>
  • <meta property='og:image' content='//media.example.com/ 1234567.jpg"/>
  • <meta property='og:description' content='Description that will show in the preview"/>
  • <meta property='og:url' content='//www.example.com/URL of the article" />

来源:LinkedIn Developer Docs: Making Your Website Shareable on LinkedIn

如果您不确定是否已正确按照 LinkedIn 文档创建共享 URL,您可以在此处测试页面的 URL,以查看共享时的外观:LinkedIn Post Inspector

【讨论】:

    【解决方案2】:

    您可以使用react-native-share 完成此操作。我已经在我的一个应用程序中使用了它。

    const shareOptions = {
      title: 'Share via',
      message: `Hello,  ${description}`,
      subject: 'Subject,
      url: "data:image/png;base64," + base64Data,
      showAppsToView: false,
      filename: 'test',
    };
    Share.open(shareOptions).then(res => {
      console.log(res)
    }).catch(e => {
      console.log(e)
    });
    

    注意:如果你能分享你的代码就更好了。

    【讨论】:

    • 你应该提到react-native-share不支持iOS上的LinkedIn图片分享
    【解决方案3】:

    您可以使用来自 react native 的链接

    import { Linking } from 'react-native';

    然后你可以使用

    Linking.openURL("https://www.linkedin.com/shareArticle?mini=true&summary=youtube&title=f1&url=https://www.youtube.com/watch?v=dQw4w9WgXcQ");

    你可以在这里找到更多信息 https://stackoverflow.com/a/10737122/6125249

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-18
      • 1970-01-01
      • 2019-09-12
      • 2018-05-11
      • 2021-11-21
      • 1970-01-01
      • 2022-06-14
      相关资源
      最近更新 更多