昨天我更改了应用程序设置并启用了“新数据权限”和“新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); } }); }); }); }
该功能只是挂起而没有任何反应。我在这个论坛上搜索了这个post
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 - 任何提示将不胜感激 感谢
答案 0 :(得分:0)
我认为这就是你要找的东西。
预先获取权限。 和 然后使用Graph API而不是Javascript SDK发布到流。 (这在发布时根本不会涉及用户,并且将在您的php代码中发生在服务器端)
答案 1 :(得分:0)
我无法找到使用Javascript的方法 - 所以我使用了php而不是
try { $statusUpdate = $facebook->api('/me/feed', 'post', array('message'=> 'example status message', 'cb' => '')); } catch (FacebookApiException $e) { }
希望它有助于某人
答案 2 :(得分:0)
尝试使用此代码在墙上发布
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.');
}
}
);
此代码适用于我的应用。希望它也能解决你的问题。