TMH*_*TMH 9 javascript facebook fb.ui
我正在使用FB.ui向Facebook分享页面,我正在尝试设置标题和消息(图像尽可能但不重要).我在我的网站标题中有这个
<meta property="og:title" content="Your title here" />
<meta property="og:description" content="your description here" />
Run Code Online (Sandbox Code Playgroud)
我的javascript代码是
FB.ui({
method: 'share',
href: document.URL,
}, function(response){
//TODO Proper response handling
log(response);
if (typeof response != 'undefined') {
alert('Thanks for sharing');
}
});
Run Code Online (Sandbox Code Playgroud)
从我读过的内容我只需要og:titleand og:description来设置标题和消息,但这似乎不起作用.
当前标题要么来自部分标题的一部分,要么来自图像上的alt标记,并且消息是从一个随机的段落标记填充的.
小智 36
汤姆,我有同样的问题,并寻找解决方案,我找到了你的帖子.也许你已经解决了它,但我想分享我发现的东西,以防它对其他人有用.Facebook文件说"分享"方法只有href参数,但我发现它不是真的.您可以使用与"feed"方法非常相似的参数.这是我使用和工作的:
FB.ui(
{
method: 'share',
href: 'your_url', // The same than link in feed method
title: 'your_title', // The same than name in feed method
picture: 'path_to_your_picture',
caption: 'your_caption',
description: 'your_description',
},
function(response){
// your code to manage the response
});
Run Code Online (Sandbox Code Playgroud)
Fai*_*aza 18
您正在使用的代码已弃用.您可以使用以下共享对话框来动态覆盖属性:
FB.ui({
method: 'share_open_graph',
action_type: 'og.shares',
display: 'popup',
action_properties: JSON.stringify({
object: {
'og:url': 'https://your-url-here.com',
'og:title': 'Title to show',
'og:description': 'The description',
'og:image': 'https://path-to-image.png'
}
})
}, function(response) {
// Action after response
});
Run Code Online (Sandbox Code Playgroud)
有关详细的工作示例,结账:http://drib.tech/programming/dynamically-change-facebook-open-graph-meta-data-javascript.
如果您在Facebook上共享网页(拥有og元标记)并稍后更新标题和描述等,它们将不会立即在Facebook上更新,因为它会缓存您的网页并在2天后再次废弃该页面.
因此,如果您想立即更新Facebook上的标题,描述等,您需要使用Facebook调试工具再次废弃网页.
OxC*_*FEE 13
这对我来说适用于2018-01-01,使用该share-open-graph方法.这是有效的,但似乎是神奇的,没有记录,所以需要注意.
shareOnFB: function() {
var img = "image.jpg";
var desc = "your caption here";
var title = 'your title here';
var link = 'https://your.link.here/';
// Open FB share popup
FB.ui({
method: 'share_open_graph',
action_type: 'og.shares',
action_properties: JSON.stringify({
object: {
'og:url': link,
'og:title': title,
'og:description': desc,
'og:image': img
}
})
},
function (response) {
// Action after response
});
Run Code Online (Sandbox Code Playgroud)
小智 7
元数据可能会被Facebook缓存.尝试在Facebook调试器中输入您的URL:https://developers.facebook.com/tools/debug/
这将清除缓存.
对于图像使用:
<meta property="og:image" content="http://yourimage">
Run Code Online (Sandbox Code Playgroud)
Facebook建议使用最小尺寸为1200x630像素的图像
| 归档时间: |
|
| 查看次数: |
32807 次 |
| 最近记录: |