我有一个rails应用程序,在该应用程序中,我必须通过fought
操作和friend
对象生成一个自定义的开放图故事,比如Peter fought his friend using appname
。
以下是我所做的。
在javascript 中
window.fbAsyncInit = function () {
FB.init({
appId: AppIDhere, // App ID
status: true, // check login status
cookie: true, // enable cookies to allow the
// server to access the session
xfbml: true, // parse page for xfbml or html5
// social plugins like login button below
version: 'v2.0', // Specify an API version
});
// Put additional init code here
};
用于加载Javascript SDK
// Load the SDK Asynchronously
(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 = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
以及点击分享按钮的功能
function postStory() {
FB.ui({
method: 'share_open_graph',
action_type: 'appNamespace:fought',
action_properties: JSON.stringify({
object: 'site_url',
friend: "friendname"
})
}, function (response) {
if (!response || response.error || response.id == undefined) {
//alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
元标签使用
<meta property='fb:app_id' content='appID'/>
<meta property="og:type" content="appNamespace:friend">
<meta property='og:url' content='site_url'/>
<meta property='og:title' content='OG title'/>
<meta property='og:image' content='google_image_url'/>
但我得到了这个奇怪的错误
"friendname" is an invalid value for property "friend" with type "Reference"
我找不到这里出了什么问题。非常感谢在这里提供的任何帮助。谢谢
确保pageURL
指向<meta property="og:type" content="appNamespace:friend">
所在的页面,请尝试:
action_properties: JSON.stringify({
'friend': {
'og:url': pageURL,
'og:type': 'appNamespace:friend',
'og:title': 'Test title',
'appNamespace:friendname': 'Some name here',
},
})