私のアプリでも作成された特定のアルバムに写真を投稿する Facebook アプリがあります。アプリを 2 回目に実行すると、別のアルバムが作成され、そこに新しい写真が投稿されます。ユーザーが新しいものを投稿した場合、写真は同じアルバムに配置され、そこにない場合は作成されます。これまでの私のコードは次のとおりです。
$graph_url = "https://graph.facebook.com/me/albums?" . "access_token=". $access_token;
$album_name = 'MyApp Album';
$album_description = 'Album description';
$postdata = http_build_query(
array('name'=> $album_name,
'message'=> $album_description
));
$opts = array('http' =>
array(
'method'=> 'POST',
'header'=> 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
));
$context = stream_context_create($opts);
$result = json_decode(file_get_contents($graph_url, false, $context));
$album_id = $result->id;
$file = $_POST['photo'];
$args = array(
'message' => 'Photo from application',
);
$args[basename($file)] = '@' . realpath($file);
$ch = curl_init();
$url = "https://graph.facebook.com/".$album_id."/photos?access_token=" . $access_token;
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);
$data = curl_exec($ch);
print_r(json_decode($data,true));
絶対に必要でない場合は、FQL クエリを使用したくありません。おそらくアルバム名を検索して ID を返すことができれば、それは素晴らしいことです。