我在从我的web应用程序中删除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不会删除任何内容。这意味着有一些新的网络开发领域,我现在必须了解…HTTP请求。
如何在php中完成这些?php手册也帮不上什么忙。
附加信息:
我试过很多不同的变体:
$facebook->api($post_url, 'DELETE', array('method'=> 'delete') );
我传递的URL是'/post_id'
。post_id
在创建后被捕获并存储到数据库中。这个id匹配$_GET['story_fbid']
,可以在任何帖子永久链接上找到。也许这不是正确的id?我正在用以下命令检索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。
尝试在删除对象ID之前添加userid,例如:
$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();
}
更新答案:
根据你的评论"这是一个页面",我看了一下图API的页面细节。如果我对细节的理解正确的话,Delete对于Page Posts是不支持的。每个连接的细节(事件,帖子,问题等)有一个创建部分,如果连接支持删除,它有一个删除描述。Posts (to feed)部分只提到了Create,而没有提到Delete。
您不能"取消发布"一篇文章,但这与删除一篇文章不同。删除一个帖子很容易。
您只需要获得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'])