I would like to know how to get image url or any other data besides id when I upload it to facebook via graph API. I tried to get image data from Graph API Explorer but it gives me false. When I put my access_token with user_photos it gives me details. However, default access token that I can get from $facebook->getAccessToken(); still gives me false.
So my question is – How can I get image data after I upload it to facebook?
Here is my code:
<?php
require 'fb/src/facebook.php';
if ($_FILES["file"]["error"] == 0)
{
// Getting
$file = $_FILES["file"];
$fileExtension = $imgExtension = end(explode(".", $file["name"]));
$upload_dir = "upload/";
// Modifying
$newName = md5(uniqid()) . "." . $fileExtension;
// Checking if this name already exists
while (file_exists($upload_dir . $newName) == true)
{
$newName = md5(uniqid()) . "." . $fileExtension;
}
// Uploading
if (move_uploaded_file($file['tmp_name'], $upload_dir . $newName) == true)
{
$facebook = new Facebook(array(
'appId' => 'app id',
'secret' => 'app secret',
));
$facebook->setFileUploadSupport(true);
$args = array(
"message" => "test caption"
);
$args['image'] = '@' . realpath($upload_dir . $newName);
$data = $facebook->api('/me/photos', 'post', $args);
print_r($data);
}
else
{
echo "Error.";
}
}
You should get the
idof uploaded photo in the response ($datain your case), simple call to Graph API with thatidshould return you all the desired info.Update: You should require
user_photosto readphotoobject details.