我想知道如何在通过Graph API将图片上传到Facebook后,获取图片URL或其他数据而不仅仅是id。我尝试从Graph API Explorer中获取图片数据,但是它给了我false
的结果。当我使用带有user_photos
的access_token
时,它会给我详细信息。然而,我可以从$facebook->getAccessToken()
获得的默认访问令牌仍然给我false
。
所以我的问题是 - 在我将图片上传到Facebook后,如何获取图片数据?
这是我的代码:
<?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.";
}
}
id
?OpenGraph Explorer工具对该id
返回什么结果? - Juicy Scripter