javascript - 如何在 React JS 中将 Image-Url 分享到 Facebook、Twitter 和 Instagram
问题描述
我有一个页面,用户可以在其中上传他们的图像并使用一个 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>
解决方案
我实施的答案如下。假设 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,getInitialProps
如果您使用的是 NEXT JS,则最后返回它。
无论提取的 URI 是什么,imageurl
我都可以添加到元og:image
标记中。
推荐阅读
- authentication - 无法获取实时环境的 PayPal 访问令牌
- javascript - 我在从 ajax 代码中获取“第 4 行 C:\xampp\htdocs\ERP\std.php 中的类”中的日期时遇到问题
- python-3.x - 如何在python中将int数组转换为字符串
- html - 如何在 VS Code 的 css 文件中检测 html 中的类名?
- android - Android studio 3.5 索引问题
- python - 将 commands.getstatusoutput 与不工作的对象结合起来?
- android - 只有状态栏透明,不是导航栏
- python - 在使用 Holoviews 或 Hvplot 时将框缩放(或平移或滚轮缩放)设置为默认值
- javascript - 我如何制作一个 fetch 函数以从需要身份验证标头的 api 获取 json 数据?
- oracle - 将 Excel-XML 转换为 XLS