迁移到Facebook Graph API
昨天我改变了应用程序设置并启用了“新数据权限”和“新SDK”。
之后,向用户墙发布消息的功能停止工作。 在我的网站上,用户使用Facebook API(图表)登录,并能够在墙上发布消息。
这是我工作正常的旧代码:
function publish_with_permission(permission,action_links,attachment) {
FB.ensureInit(function() {
FB.Connect.requireSession(function(){
//check is user already granted for this permission or not
FB.Facebook.apiClient.users_hasAppPermission(permission,
function(result) {
// prompt offline permission
if (result == 0) {
// show the facebook permission dialog
FB.Connect.showPermissionDialog(permission,
function(result){
if (!result) {
FB.Connect.streamPublish('', attachment, action_links, null, "Post this:", jscallback);
} else {
// permission granted, post without facebook dialog
FB.Connect.forceSessionRefresh(function() {
FB.Connect.streamPublish('', attachment, action_links, null, "Post this:", jscallback,true);
});
}
}, true, null);
} else {
// permission already granted, post suddenly
// without facebook dialog
FB.Connect.streamPublish('', attachment, action_links, null, "Post this:", jscallback,true);
}
});
});
});
}
该功能只是挂起,没有任何反应。 我在这个论坛上搜索,发现这个职位
function fb_publish() {
FB.ui(
{
method: 'stream.publish',
message: 'Message here.',
attachment: {
name: 'Nom ici.',
caption: 'Caption here.',
description: (
'description here'
),
href: 'url here'
},
action_links: [
{ text: 'Code', href: 'action url here' }
],
user_prompt_message: 'Personal message here'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}
这个工作,但它有两个问题1)即使当用户第一次使用图形API登录,并且他们已经授予扩展权限发布到他们的墙上时,此方法每次都会询问用户是否允许 - 先前一个没有这样做。 2)这种方法还允许用户添加他们的评论 - 我不想要这个。
我想无缝地发布到墙上,而无需再次明确地询问他们之前已经授予的权限。
我正在使用PHP - 任何提示将不胜感激谢谢
我认为这是你要找的。
预先获得权限。 然后使用Graph API而不是Javascript SDK进行发布。 (这在发布时不会涉及用户,并且会在您的php代码中在服务器端发生)
我无法弄清楚用Javascript做到这一点 - 所以我用了PHP代替
try
{
$statusUpdate = $facebook->api('/me/feed', 'post', array('message'=> 'example status message', 'cb' => ''));
}
catch (FacebookApiException $e)
{
}
希望它能帮助别人
尝试使用此代码在墙上发布
FB.ui(
{
method: 'feed',
name: 'NAME',
link: 'LINK OF THE WEBSITE OR PAGE',
picture: 'IMAGE_URL IF YOU NEED IT',
caption: 'Reference Documentation',
description: "DESCRIPTION"
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
此代码适用于我的应用程序。 希望它也能解决你的问题。
链接地址: http://www.djcxy.com/p/49597.html