Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Facebook Graph API在特定应用程序相册中发布图片_Facebook_Facebook Graph Api_Facebook Fql_Facebook Php Sdk - Fatal编程技术网

Facebook Graph API在特定应用程序相册中发布图片

Facebook Graph API在特定应用程序相册中发布图片,facebook,facebook-graph-api,facebook-fql,facebook-php-sdk,Facebook,Facebook Graph Api,Facebook Fql,Facebook Php Sdk,我有一个Facebook应用程序,可以将图片发布到我的应用程序创建的特定相册中。如果我第二次运行该应用程序,它将创建另一个相册并在那里发布新图片。我想如果用户发布一个新的,图片要放在同一个相册,如果没有被创建。以下是我目前的代码: $graph_url = "https://graph.facebook.com/me/albums?" . "access_token=". $access_token; $album_name = 'MyApp Album'; $album_description

我有一个Facebook应用程序,可以将图片发布到我的应用程序创建的特定相册中。如果我第二次运行该应用程序,它将创建另一个相册并在那里发布新图片。我想如果用户发布一个新的,图片要放在同一个相册,如果没有被创建。以下是我目前的代码:

$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,那就太好了

a)您尝试过什么,b)为什么您要手动执行这些操作而不是使用PHP SDK(您用它标记了这个问题,但实际上没有在任何地方使用)?我尝试过使用FQL查询根据唱片集名称检索唱片集ID:“MyApp album”如果没有像这样命名的相册,请继续创建一个新的相册,但我不喜欢使用fql查询,但我不知道另一个方法。b) 它对我来说只是卷曲,也许我没有像它应该的那样使用它?