【发布时间】:2020-06-01 22:41:30
【问题描述】:
我有一个内置 react-native 的应用,我需要在 LinkedIn 上分享包含预定义内容的帖子。
我使用“react-native-share”在 LinkedIn 上分享内容,但它不起作用。我怎样才能做到这一点?
提前致谢。
【问题讨论】:
-
请添加您的代码
标签: react-native linkedin
我有一个内置 react-native 的应用,我需要在 LinkedIn 上分享包含预定义内容的帖子。
我使用“react-native-share”在 LinkedIn 上分享内容,但它不起作用。我怎样才能做到这一点?
提前致谢。
【问题讨论】:
标签: react-native linkedin
LinkedIn 只支持传递给它的一个参数,那就是url 参数。它看起来像这样......
https://www.linkedin.com/sharing/share-offsite/?url={url}
来源:Official LinkedIn Sharing Documentation。
以下参数将不起作用:summary、title、source 等。除了url 之外的任何参数。
要分享到 LinkedIn,只需创建一个指向上述格式化 URL 的 <a href> 元素,并确保对您的 {url} 进行 URL 编码。
不过,根据接受的答案,您可能想分享title 和summary。你不能使用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。
【讨论】:
您可以使用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图片分享
您可以使用来自 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
【讨论】: