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

问题描述:

我正在尝试熟悉 Facebook 的新 Graph API,到目前为止我可以很容易地获取和写入一些数据.

I'm trying to familiarize myself with Facebook's new Graph API and so far I can fetch and write some data pretty easily.

我正在努力寻找有关将图像上传到相册的相关文档.

Something I'm struggling to find decent documentation on is uploading images to an album.

根据http://developers.facebook.com/docs/api#publishing 您需要提供 message 参数.但我不太确定如何构建它.

According to http://developers.facebook.com/docs/api#publishing you need to supply the message argument. But I'm not quite sure how to construct it.

我读过的旧资源是:

https://developers.facebook.com/docs/参考/rest/photos.upload/

如果有人有更多信息或可以帮助我解决使用 Facebook Graph API 将照片上传到相册的问题,请回复!

If someone has more information or could help me tackle uploading photos to an album using Facebook Graph API please reply!

这里有一些使用 PHP Facebook Graph API 上传照片的各种方法.这些示例假设您已经实例化了 $facebook 对象并且有一个有效的会话.

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

此示例会将照片上传到当前用户的默认应用程序相册.如果相册尚不存在,则会创建它.

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.

$facebook->setFileUploadSupport(true);
$args = array('message' => 'Photo Caption');
$args['image'] = '@' . realpath($FILE_PATH);

$data = $facebook->api('/me/photos', 'post', $args);
print_r($data);

2 - 上传到目标相册

此示例会将照片上传到特定相册.

2 - Upload to Target Album

This example will upload the photo to a specific album.

$facebook->setFileUploadSupport(true);
$args = array('message' => 'Photo Caption');
$args['image'] = '@' . realpath($FILE_PATH);

$data = $facebook->api('/'. $ALBUM_ID . '/photos', 'post', $args);
print_r($data);