如何通过抓住api php与curl删除照片帖子id facebook

时间:2013-10-11 23:04:34

标签: php facebook curl

我尝试删除我用PHP上传的应用程序上传的照片

上传示例的结果:

 {"id":"429774393794352","post_id":"276744849097308_429774413794350"} 

首先使用一个id或post_id

以及如何用php选择它?

以及如何通过curl库使用php代码删除它

我的想法是,我会将所有照片ID存储到sql中以便随时删除

我使用的上传代码

$file='./'.$new_string;






$args = array(
   'message' => $message,
);
$args[basename($file)] = '@' . realpath($file);
$ch = curl_init();
$url = 'https://graph.facebook.com/album id /photos?access_token='.$accsesss;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$a1=$data = curl_exec($ch);
print_r(json_decode($data,true));
echo'<br/>';

我试试

$args = array(
   'id' => '276744849097308_429774413794350',
   'access_token' => $accsesss ,


);
$ch = curl_init();
$url = 'https://graph.facebook.com/276744849097308_429774413794350?method=DELETE&access_token=$accsesss';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true); $a1=$data = curl_exec($ch);
print_r(json_decode($data,true));
echo'<br/>';

结果

Array ( [error] => Array ( [message] => Invalid OAuth access token. [type] => OAuthException [code] => 190 ) ) 

1 个答案:

答案 0 :(得分:1)

 $Curl_Session = curl_init('https://graph.facebook.com/429774393794352');
 curl_setopt ($Curl_Session, CURLOPT_POST, 1);
 curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "method=DELETE&access_token=$masteracsess");
 curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($Curl_Session, CURLOPT_RETURNTRANSFER, 1);

 echo $a8=curl_exec ($Curl_Session);
 curl_close ($Curl_Session);

感谢您的帮助@CBroe