Graph:Photo

From Facebook Developer Wiki (FbDevWiki.com)
Jump to: navigation, search

An individual photo within an album

Contents

Example

https://graph.facebook.com/98423808305 (A photo from the Coke fan page)

Properties

Name Description Permissions Returns Condition
id The photo's ID Available to everyone on Facebook by default A JSON string
from The profile (user or page) that posted this photo Available to everyone on Facebook by default A JSON object containing id and name fields
tags The tagged users and their positions in this photo Available to everyone on Facebook by default An array of JSON objects, the x and y coordinates are percentages from the left and top edges of the photo, respectively only if tags exist
name The caption given to this photo Available to everyone on Facebook by default A JSON string
icon The icon that Facebook displays when photos are published to the Feed Available to everyone on Facebook by default A JSON string contain a valid URL if return_ssl_resources=1 then will return https version of icon
picture thumbnail size of the photo A JSON string contain a valid URL if return_ssl_resources=1 then will return https version of picture
source The largest of the resized photos or the source photo originally uploaded Available to everyone on Facebook by default A JSON string contain a valid URL if return_ssl_resources=1 then will return https version of picture
height The height of the photo in pixels Available to everyone on Facebook by default A JSON number
width The width of the photo in pixels Available to everyone on Facebook by default A JSON number
images An array of objects describing all the different sizes available and including the original photo if available array of JSON objects containing height, width, and source if return_ssl_resources=1 then will return https version of picture
link A link to the photo on Facebook Available to everyone on Facebook by default A JSON string contain a valid URL
place place associated with photo (if available) A JSON object containing id and name of Page associated with this location, and a location field containing geographic information such as latitude, longitude, country, and other fields (fields will vary based on geography and availability of information)
created_time The time the photo was initially published Available to everyone on Facebook by default A JSON string containing a IETF RFC 3339 datetime unless altered with date_format
updated_time The last time the photo or its caption was updated Available to everyone on Facebook by default A JSON string containing a IETF RFC 3339 datetime unless altered with date_format
position ordinal position in the album integer
comments seems to contain the same information as the "comments" connection A JSON object
likes seems to contain the same information as the "likes" connection JSON string only visible if fields=likes

Connections

Name Description Permissions Returns
comments All of the comments on this photo Available to everyone on Facebook by default An array of JSON objects containing id, from, message and created_time fields
likes Users who like the photo Available to everyone on Facebook by default An array of JSON objects containing id and name fields
picture The album-sized view of the photo Available to everyone on Facebook by default An HTTP 302 with the location of the picture URL. (use ?type=thumbnail | normal | album to request a different photo size, default is "normal")

Publishing

Requires the publish_stream permission.

To publish a photo, issue a POST request with the photo file attachment as multipart/form-data.

You can publish an individual photo to a user profile with a POST to http://graph.facebook.com/PROFILE_ID/photos . Facebook automatically creates an album for your application if it does not already exist. All photos from your application will be published to the same automatically created album.

You can publish a photo to a specific, existing photo album with a POST to http://graph.facebook.com/ALBUM_ID/photos.

If you would like to suppress the story that is automatically generated in the user's feed when you publish a photo (usually because you plan on generating your own), you can add a no_story=1 parameter. In this case, the user will receive a notification that your application has uploaded a photo.

curl -F 'access_token=...' \
     -F 'source=@file.png' \
     -F 'message=Caption for the photo' \
     -F 'tags=[{"tag_uid":"4","x":"20","y":"20"}]' \
     https://graph.facebook.com/me/photos

PHP example of above:

require './facebook.php';
$facebook = new Facebook(array(
	'appId'  => 'YOUR APP ID',
	'secret' => 'YOUR API SECRET',
	'cookie' => true, // enable optional cookie support
));

$facebook->setFileUploadSupport(true);  // can also be set when creating Facebook object
$result = $facebook->api('/me/photos', 'post', array(
		'source' => '@file.png',
		'message' => 'Caption for the photo',
		'tags' => '[{"tag_uid":"4","x":"20","y":"20"}]'
	));


Deleting

As of 14 June 2011 it's no longer possible to delete user photos and albums from your application.

Notes

PHP example on how to send more than one file via CURL:

    $post_data = array();
    $post_data['pictures[0]'] = "@cat.jpg";
    $post_data['pictures[1]'] = "@dog.jpg";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://example.com/my_url.php" );
    curl_setopt($ch, CURLOPT_POST, 1 );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $postResult = curl_exec($ch);

    if (curl_errno($ch)) {
       print curl_error($ch);
    }
    curl_close($ch);
    print "$postResult";
Personal tools
Namespaces
Variants
Actions
Navigation
Graph API
FQL
Toolbox