Upload images to a specific Facebook Album

前端 未结 2 1743
滥情空心
滥情空心 2021-01-05 22:24

I can create an album using facebook graph api by posting data to

http://graph.facebook.com/ALBUM_ID/albums

it returns an id, which is not

2条回答
  •  情歌与酒
    2021-01-05 22:30

    The new php-sdk is working just fine, I've just tested it and here are my comments:

    1.Make sure you have the right extended permission which is publish_stream for both Album creation and Photo upload.

    2.After creating the Album using the below code, you'll receive the Album ID:

    $post_data = array(
        'name'=>"My Test Album",
        'description'=>"My Test Album Desc"
        );
    $data['album'] = $this->facebook->api("/me/albums", 'post', $post_data);  
    

    P.S: I confirm this ID is NOT the ID you see when browsing Facebook

    3.Now we need to upload the image with the Album "reference" ID you got:

    $file = FCPATH . "assets/img/small1.jpg";
    $post_data = array(
        "message" => "My photo caption",
        "source" => '@' . realpath($file)
    );
    $album_id = "473425002142";
    $data['photo'] = $this->facebook->api("/$album_id/photos", 'post', $post_data);  
    

    P.S: the Constant FCPATH is a Codeigniter constant, you can you $_SERVER['DOCUMENT_ROOT'] or whatever method you are comfortable with.

    And the result:
    alt text

提交回复
热议问题