2
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.

PSS

我实际上是在创建对象实例、对象记录还是其他东西?

4

1 回答 1

1

文档中

标准对象属性被添加到您传递到调用以创建对象的 JSON 对象的顶层。

任何不是标准对象属性的属性都应作为 data: {...} 元素包含在您在创建对象时传入的 JSON 对象上。这是包含海拔自定义属性的自定义山脉类型的示例;

{
  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
  }
}

此格式与通过 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
  }
);
于 2013-10-15T19:18:51.937 回答