我的代码用于在测验表单末尾动态创建Facebook Share Results按钮。除name
设置外,代码均正常工作。首先,这是PHP代码:
$ret = <<<EOT
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '{$settings_Facebook["appId"]}',
xfbml : true,
version : 'v2.7'
});
};
(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'));
// calling the API ...
function postToFeed() {
var obj = {
method: 'feed',
redirect_uri: '{$settings_Facebook['redirect_uri']}',
link: '{$settings_Facebook['link']}',
picture: '{$settings_Facebook['picture']}',
name: '{$settings_Facebook['name']}',
caption: '{$settings_Facebook['caption']}',
description: '{$settings_Facebook['description']}',
};
function callback(response) {
//document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}
FB.ui(obj, callback);
}
</script>
<div id="msg" width="100%; height: 50px;"></div>
<div style="float: right; padding: 8px; overflow: hidden;">
<a href="#" onClick="postToFeed()">Share results!</a>
</div>
EOT;
以上代码在HTML中呈现为:
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '439873598753987',
xfbml : true,
version : 'v2.7'
});
};
(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'));
// calling the API ...
function postToFeed() {
var obj = {
method: 'feed',
redirect_uri: 'https://example.com/quiz/',
link: 'https://example.com/quiz/',
picture: 'https://example.com/images/quiz-categories_0000.jpg',
name: 'I ranked 1 in this online quiz! Take it yourself!',
caption: 'EXAMPLE.COM',
description: 'Aliquam in magna.',
};
function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}
FB.ui(obj, callback);
}
</script>
出于我的目的,上述代码和输出完全正确。弹出共享对话框时,预览看起来100%正确,name
字段显示为:
I ranked 1 in this online quiz! Take it yourself!
但是发给用户FB页面的帖子包含name
字段中的WordPress标语:
My site's custom tagline.
我不能肯定正在使用标语。我略微改变它并没有影响新的Facebook帖子,但它可能会在某个地方缓存。我无法想到这个文本的配置位置 - 恰好也就是网站的标语。 :S
为什么Facebook会覆盖我在API调用的name
属性中指定的内容?即使它是由FB设计的,我该如何克服这个?
答案 0 :(得分:1)
这确实是一个错误,上周四由Facebook证实。 https://developers.facebook.com/bugs/1214328271924404/
我们希望很快就能解决。