[英]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.