[英]Deleting a Facebook Post from a Page with $facebook->api
我无法从我的网络应用程序中删除Facebook帖子。 现在我知道Facebook文档和其他SO帖子说要做到这一点:
You can delete objects in the graph by issuing HTTP DELETE requests to
the object URLs, i.e,
DELETE https://graph.facebook.com/ID?access_token=... HTTP/1.1
但由于我是一个菜鸟,我不完全理解用HTTP请求删除的简短说明。 因为当我尝试时它不起作用,我认为在上面的例子中简单地重定向到形成的url不会删除任何东西。 这意味着我现在必须了解一些新的Web开发领域...... HTTP请求。
这些如何在PHP中完成? php手册也没有多大帮助。
我尝试了很多不同的变体:
$facebook->api($post_url, 'DELETE', array('method'=> 'delete') );
我传递的网址是'/post_id'
。 post_id
在创建后捕获并存储到数据库中。 此ID与$_GET['story_fbid']
匹配,可以在任何帖子固定链接上找到。 也许这不是正确的身份证? 我正在使用以下内容检索id:
//post to wall
$postResult = $facebook->api($post_url, 'post', $msg_body );
//capture the id of the post
$this->fb_post_id = $postResult['id'];
当我运行上面的代码时,不会抛出任何错误。 它被触摸是因为它运行后的诊断echo
。
这些是我用$post_url
传递给api的字符串的不同组合:
/postid api returns true, nothing is deleted from Facebook
/userid_postid api returns false, Error: (#100) Invalid parameter
/postid_userid api returns false, Error: (#1705) : Selected wall post for deletion does not exist
/accesstoken_postid api returns false, Error: (#803) Some of the aliases you requested do not exist
/postid_accestoken api returns false, Error: (#803) Some of the aliases you requested do not exist
这应该工作:
$facebook->api("/YOUR_POST_ID","DELETE");
将返回一个布尔值,如果成功则返回true,如果失败则返回false。
尝试在删除时将userid预先添加到对象ID,例如:
$facebook->api("/USER-ID_YOUR-POST-ID","DELETE");
喜欢:
$facebook->api("/12345132_5645465465454","DELETE");
//where 12345132 is fb userid and
//5645465465454 is object id --> post id
我已成功使用具有read_stream和manage_pages权限的页面访问令牌从页面中删除帖子。
try {
$args = array(
'access_token' => $page_token
);
$deleted = $facebook->api('/'.$post_id, 'DELETE', $args);
} catch (FacebookApiException $e) {
echo 'Delete review page wall error: ' . $e->getType() . ' ' . $e->getMessage();
}
更新的答案:
根据您的评论“这是一个页面”,我看了一下Graph API的页面详细信息。 如果我理解正确的详细信息, 则不支持删除页面帖子 。 详细信息中的每个连接(事件,帖子,问题等)都有一个“创建”部分,如果“连接”支持“删除”,则它具有“删除”描述。 帖子(提要)部分仅提及创建,而不是删除。
您不能“取消发布”帖子,但这与删除帖子不同。 删除帖子非常简单。
您只需要获取COMMENT_ID并将其发布到Facebook。
$post_url = 'https://graph.facebook.com/'. $COMMENT_ID .'?access_token=' . $page_access_token . '&method=delete';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);
为了澄清这一点:如果您有权管理帖子,那么这可以在Page API之外使用。
我能够使用php SDK 5.4从页面删除帖子
$post = $fb->request('DELETE', '/'.$post_id,[], $page['accesstoken'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.