Javascript 如何在React JS中共享Facebook、twitter和Instagram的图像Url
我有一个页面,用户可以上传他们的图像,并使用一个Api进行编辑 现在,使用收到的url格式的图像需要在Facebook、Twitter和Instagram等社交媒体上共享 以下是用于社交媒体重定向的Url: Facebook-${window.location.href}?imageurl=${imageurl} Twitter-${window.location.href}?imageurl=${imageurl} Instagram-尚未找到 尝试过的事情: 尝试使用componentDidMount中的createElement和setAttribute将状态存储的{imageUrl}动态添加到meta标记中,该组件未在facebook中更新此图像,但能够在og:image in head->meta标记中添加此图像。 请为我提供一些解决方案。这将是一个很大的帮助Javascript 如何在React JS中共享Facebook、twitter和Instagram的图像Url,javascript,reactjs,twitter,instagram,share,Javascript,Reactjs,Twitter,Instagram,Share,我有一个页面,用户可以上传他们的图像,并使用一个Api进行编辑 现在,使用收到的url格式的图像需要在Facebook、Twitter和Instagram等社交媒体上共享 以下是用于社交媒体重定向的Url: Facebook-${window.location.href}?imageurl=${imageurl} Twitter-${window.location.href}?imageurl=${imageurl} Instagram-尚未找到 尝试过的事情: 尝试使用componentDid
<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)
无论从
imageurl
中提取的URI是什么,我都可以添加到metaog:image
标签中。如果您想尝试npm软件包,请尝试使用“react share”软件包。