var hashid = 'abc123';
var title = 'Awesome Widget';
FB.api( // creating the widget object instance/record
'me/objects/myapp:widget',
'post',
{
object: JSON.stringify({
'app_id': <obfuscated>,
'url': 'http://example.com/' + hashid, // maps to og:url
'title': 'widget', // maps to og:title
'myapp:real_title': title, // maps to nothing right now! No bueno!
'image': { // maps to og:image
'url': 'http://example.com/images/' + hashid
},
'description': 'Man, this widget is awesome!' // maps to og:description
})
},
function(response) {
// handle the response
}
);
是的,我已经创建了自定义“widget”对象和自定义“real_title”属性。正在创建对象,但不包括“real_title”属性:
我是否需要在对象实例/记录中为每个属性指定特殊语法(og:title
等)?
附言
我希望 og:title
只是“小部件”,因为我想以特定方式创建用户故事。因此,还需要指定 real_title
。
附言
我实际上是在创建对象实例、对象记录还是其他东西?
最佳答案
来自 the documentation :
Standard object properties are added to the top-level of the JSON object that you pass into your call to create an object.
Any property that's not a standard object property should be included as a data: {...} element on the JSON object you pass in when creating an object. Here's an example of a custom mountain type that includes an elevation custom property;
{
title: 'Mt. Rainier',
type: 'myapp:mountain',
image: 'http://en.wikipedia.org/wiki/File:Mount_Rainier_5917s.JPG',
url: 'https://url.to.your.app/example/mountains/Mt-Rainier',
description: 'Classic cold war technothriller',
data: {
elevation: 14411
}
}
This format is the same as what an object looks like when it's read back from the database via the Graph API.
简而言之,您需要执行以下操作:
var hashid = 'abc123';
var title = 'Awesome Widget';
FB.api( // creating the widget object instance/record
'me/objects/myapp:widget',
'post',
{
object: JSON.stringify({
'app_id': <obfuscated>,
'url': 'http://example.com/' + hashid, // maps to og:url
'title': 'widget', // maps to og:title
'image': { // maps to og:image
'url': 'http://example.com/images/' + hashid
},
'description': 'Man, this widget is awesome!', // maps to og:description
'data': {
'real_title': title // maps to myapp:real_title
}
})
},
function(response) {
// handle the response
}
);
关于javascript - 如何使用自定义属性创建/发布 Open Graph 对象实例/记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19388297/