Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a Facebook Post from a Page with $facebook->api

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.


Additional Information:

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
like image 496
Jonathan Eckman Avatar asked Dec 24 '12 03:12

Jonathan Eckman


People also ask

Can moderator delete post on Facebook page?

Admins and moderators can remove posts from their group and give feedback about why the post was removed.

Can I post on Facebook using API?

The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.


1 Answers

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
like image 69
Sudhir Bastakoti Avatar answered Sep 24 '22 15:09

Sudhir Bastakoti