如何使用Facebook Graph API将照片上传到相册

问题描述:

这是代码:

$file= 'bbbb.jpg';
$data = array(
            basename($file) => "@".realpath($file),
            "caption" => "Uploaded using graph api",
            "aid" => '13595',
            "access_token" => $accessToken,
            'method' => 'photos.upload'
);
$sds =$facebook->api($data);

这是错误


未捕获CurlException:26:创建formpost数据失败

Uncaught CurlException: 26: failed creating formpost data

该怎么办?

以下是使用Graph API上传照片的各种方法。这些例子假设你已经实例化了$ facebook对象,并为当前用户提供了一个有效的会话。

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.

此示例将照片上传到当前用户的默认应用程序专辑。如果专辑不存在,它将被创建。

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 - 目标相册



将照片上传到特定的专辑。

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 - 具有访问令牌的目标相册



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);