在Facebook上共享时,我使用Open Graph使我的网站漂亮。我具有以下元标记:
<meta property="og:url" content="url">
<meta property="og:title" content="title">
<meta property="og:image" content="img">
<meta property="og:type" content="website">
<meta property="og:description" content="desc">
<meta property="fb:app_id" content="908069756051947" />
这很好用。现在,我想动态更改它,因此我包含了这样的Facebook SDK:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '908069756051947',
autoLogAppEvents : true,
xfbml : true,
version : 'v3.1'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
体内标签。而且我会像这样动态地更改它们(仅当URL中有子字符串“ id”时):
FB.ui(
{
method: 'share_open_graph',
action_type: 'og.shares',
action_properties: JSON.stringify({
object: {
'og:url': "new_url",
'og:title': "new_title",
'og:description': "new_desc",
'og:image': "new_img"
}
})
},
function(response) {
}
);
现在,我需要的是,如果URL中包含“ id”并像在Facebook上那样共享,我希望Facebook显示新生成的属性,但是会显示旧属性。该如何解决?