Home  >  Article  >  Backend Development  >  How to Upload Photos to Facebook Albums Using the Graph API?

How to Upload Photos to Facebook Albums Using the Graph API?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-23 02:42:12263browse

How to Upload Photos to Facebook Albums Using the Graph API?

Uploading Photos to Albums with Facebook's Graph API

Overview

Uploading images to Facebook albums using their Graph API requires a specific "message" argument. The documentation around its construction can be confusing.

Solution

1. Default Application Album

To upload a photo to the default album of the current user, utilize the following syntax:

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

2. Target Album

For uploading to a specific album, follow this format:

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

The above is the detailed content of How to Upload Photos to Facebook Albums Using the Graph API?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn