2

編集:

<?php
    $file= 'fbplus.jpg';

    $args = array(
       'message' => $album_message,
    );
    $args[basename($file)] = '@' . realpath($file);
    $ch = curl_init();
    $url = $graph_url;
    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);
    //returns the photo id
    print_r(json_decode($data,true));


    echo "$data['id'] "; //wont work
        echo "$data[id] "; //wont work


?>

これは、写真のアップロードに成功した後の返品でした。

配列 ([id] => 112235735579158 [post_id] => 100003781972892_112203478915717)

4

2 に答える 2

2

curl_exec()ではなく、文字列 (Web ページのコンテンツ) を返しますArray。配列ではなく文字列である$data['id']ため、実行できません。$data

投稿先のURLは?その正確な出力は何ですか?

編集: URL が JSON を返すようです。その場合:

<?php
    $file= 'fbplus.jpg';

    $args = array(
       'message' => $album_message,
    );
    $args[basename($file)] = '@' . realpath($file);
    $ch = curl_init();
    $url = $graph_url;
    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);
    //returns the photo id

    $data = json_decode($data,true);

    echo $data['id'];
?>
于 2012-04-28T10:48:48.413 に答える
0

Facebook Graph API にアクセスしていますか?

もしそうなら、次を使用してください:

$data = json_decode($data);

そこからアクセスできます$data->id

于 2012-04-28T10:49:47.373 に答える