【问题标题】:How to share Image-Url to Facebook, twitter and Instagram in React JS如何在 React JS 中将 Image-Url 分享到 Facebook、Twitter 和 Instagram
【发布时间】:2020-05-06 16:55:27
【问题描述】:

我有一个页面,用户可以在其中上传他们的图像并使用一个 Api 对其进行编辑。

现在使用收到的图片,以 url 格式,需要在 Facebook、Twitter 和 Instagram 等社交媒体上分享。

以下是用于社交媒体重定向的 URL:

Facebook -https://www.facebook.com/sharer.php?u=${window.location.href}?imageurl=${imageUrl} Twitter-https://twitter.com/intent/tweet?url=${window.location.href}?imageurl=${imageUrl} Instagram-尚未找到一个

尝试过的事情: 尝试使用 componentDidMount 中的 createElement 和 setAttribute 动态地将存储在状态中的 {imageUrl} 添加到元标记中,这没有在 facebook 中更新此图像,但能够在 og:image 中添加此图像到 head->meta 标记中。 请为我提供一些解决方案。这将是一个很大的帮助。

           <a
            data-pgaction-redirection="0"
            target="_blank"
            rel="noopener noreferrer"
            title={title}
            href=`{https://www.facebook.com/sharer.php?u=${window.location.href}? 
            imageurl=${this.state.imageUrl}}`
          >
           Facebook
          </a>

【问题讨论】:

  • 如果你愿意尝试一个 npm 包,试试 'react-share' 包。

标签: javascript reactjs twitter instagram share


【解决方案1】:

我实现的答案如下。假设 Facebook URL 是

https://www.facebook.com/sharer.php?u=https:example.com?imageurl=${this.state.imageUrl}}

您可以将动态图像 URL 附加到 imageurl 属性,Facebook 的爬虫将转到 https:example.com/imageurl=https://imageurl.url.com。 然后,您必须提取查询参数并附加imageurl-URI,如果您使用的是NEXT JS,最后从getInitialProps返回。

无论从 imageurl 提取的 URI 是什么,我都可以将其添加到元 og:image 标记中。

【讨论】:

  • instagram 的分享链接是什么?
  • 它不起作用!如何获取 Instagram 用户头像并在 img 标签 html 中显示?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-08
  • 1970-01-01
  • 2017-12-21
  • 2011-11-10
  • 1970-01-01
  • 2019-03-08
相关资源
最近更新 更多