How can I upload photos to album using Facebook Graph API

后端 未结 3 549
半阙折子戏
半阙折子戏 2020-12-11 10:37

Here is the code:

$file= \'bbbb.jpg\';
$data = array(
            basename($file) => \"@\".realpath($file),
            \"caption\" => \"Uploaded using         


        
3条回答
  •  情书的邮戳
    2020-12-11 10:50

    Here are some various ways to upload photos using the Graph API. The examples assume you've instantiated the $facebook object and have a valid session for the current user.

    1 - Default Application Album of Current User

    This example will upload the photo to your default application album of the current user. If the album does not yet exist it will be created.

    $args = array('message' => 'Photo Caption');
    $args['image'] = '@' . realpath($FILE_PATH);
    
    $data = $facebook->api('/me/photos', 'post', $args);
    print_r($data);
    

    2 - Target Album

    This example will upload the photo to a specific album.

    $args = array('message' => 'Photo Caption');
    $args['image'] = '@' . realpath($FILE_PATH);
    
    $data = $facebook->api('/'. $ALBUM_ID . '/photos', 'post', $args);
    print_r($data);
    

    3 - Target Album with Access Token

    This example will upload a photo to a specific album which requires an access token.

     $args = array('message' => 'Photo Caption');
    $args['image'] = '@' . realpath($FILE_PATH);
    
    $data = $facebook->api('/'. $ALBUM_ID . '/photos?access_token='. $ACCESS_TOKEN, 'post', $args);
    print_r($data);
    

提交回复
热议问题