Delete facebook post with Graph API - trouble getting this to work

痞子三分冷 提交于 2019-12-06 22:56:58

问题


I'm using the following to post a message on my Facebook page:

$attachment =  array(
    'access_token' => $access_token,
    'message' => 'This is a test Message 4:',   
    'name' => "This is a test Name 4",
    'link' => "http://slashdot.org/",
    'description' => "This is a test Description 4"
);

$ret_code=$facebook->api('/me/feed', 'POST', $attachment);

This works great.

How do I delete the same post using the facebook GRAPH api? I read the docs and it says to issue a POST like:

https://graph.facebook.com/COMMENT_ID?method=delete

To test I set this up in a simple form with submit button, POSTing the data to https://graph.facebook.com/COMMENT_ID?method=delete (substituting COMMENT_ID fro the 11111111111_111111111111 id returned from the original publish call. This returns "This API call requires a valid app_id".

What is the correct way to issue a DELETE command?


回答1:


Since you are using the php-sdk you just issue this call:

$facebook->api("/COMMENT_ID","DELETE");



回答2:


You can use the following code:

Http::post('https://graph.facebook.com/'.$fb_action_id, array('method'=>'delete', 'access_token'=>$your_app_access_token));

This post will return a boolean value, true if successed and false if failed.




回答3:


Its been discussed here Facebook SDK and Graph API Comment Deleting Error




回答4:


you need to pass the access token too. You can delete all the milestones of a page like follows:

$milestones = $facebook->api('/PAGE_ID/milestones');
foreach($milestones[data] as $milestone)
{
  echo $milestone['id'];
  $args = array(
    'access_token'  => $pages_access_token
  );
  $deleted = $facebook->api($milestone['id'],"delete",$args);
  if($deleted)
  {
    echo " <font color=\"green\">OK</font><br>";
  }
  else
  {
    echo " <font color=\"red\">ERR</font><br>";
  }
}


来源:https://stackoverflow.com/questions/5939485/delete-facebook-post-with-graph-api-trouble-getting-this-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!