Reputation: 2077
I am having trouble deleting a facebook post from my web app. Now I know the Facebook documentation and other SO posts say to do this:
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
But since Im such a noob, I dont fully understand the short explanation of deleting with an HTTP request. Since it did not work when I tried, I assume that simply redirecting to the formed url in the example above does not delete anything. This means theres some new area of web development that I now have to understand... HTTP requests.
How are these done in php? The php manual isnt helping much either.
I have tried many different variations of:
$facebook->api($post_url, 'DELETE', array('method'=> 'delete') );
The URL I am passing is '/post_id'
. The post_id
is being captured at post creation and stored into the database. This id matched the $_GET['story_fbid']
that can be found on any post permalink. Perhaps this is not the correct id? I am retrieving the id with the following:
//post to wall
$postResult = $facebook->api($post_url, 'post', $msg_body );
//capture the id of the post
$this->fb_post_id = $postResult['id'];
When I run the code above, no errors are thrown. It is being touched because a diagnostic echo
after it is running.
These are the different combinations of strings I have passed to api with $post_url
:
/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
Upvotes: 5
Views: 10386
Reputation: 1406
I was able to delete post from page using php SDK 5.4 using this
$post = $fb->request('DELETE', '/'.$post_id,[], $page['accesstoken'])
Upvotes: 0
Reputation: 1
You cannot "unpublish" a post but this isn't the same as deleting a post. Deleting a post is quite easy.
You only need to get the COMMENT_ID and post it to 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);
To clarify this: this works outside of the Page API if you have the rights to manage the posts.
Upvotes: 0
Reputation: 161
I have had success deleting posts from a page using the page access token with read_stream and manage_pages permissions.
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();
}
Upvotes: 1
Reputation: 28470
Updated answer:
Based on your comment "this is a page" I had a look at the Graph API's Page details. If I understand the details right, Delete is unsupported for Page Posts. Each connection in the details (Events, Posts, Question etc) have a Create section and if the Connection supports Delete it has a Delete description. The Posts (to feed) section only mentions Create, not Delete.
Upvotes: 0
Reputation: 100175
This should work:
$facebook->api("/YOUR_POST_ID","DELETE");
will return a boolean value, true if successed and false if failed.
Try prepending userid to the object ID when deleting, like:
$facebook->api("/USER-ID_YOUR-POST-ID","DELETE");
like:
$facebook->api("/12345132_5645465465454","DELETE");
//where 12345132 is fb userid and
//5645465465454 is object id --> post id
Upvotes: 4