你能告诉我我做错了什么吗?我使用 PHP。尝试将照片上传到用户个人资料中。我获得了权限并且它有效。但是上传不起作用,我尝试了很多方法。那么我做错了什么?
<?php
include_once 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'ID',
'secret' => 'SECRET',
'cookie' => true,
'domain' => 'DOMAIN',
'fileUpload' => 'true'
));
$session = $facebook->getSession();
if (!$session) {
$loginUrl = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 1,
'display' => 'page',
'req_perms' => 'user_likes, publish_stream',
'next' => 'NEXTURL'
));
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
} else{
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$token = $session['access_token'];//here I get the token from the $session array
$album_id = 'ALBUM ID'; /// what should I write here?
//upload your photo
$file= 'logo.png';
$args = array(
'message' => 'Photo from app',
);
$args[basename($file)] = '@' . realpath($file);
$ch = curl_init();
$url = 'https://graph.facebook.com/'.$album_id.'/photos?access_token='.$token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
//returns the id of the photo you just uploaded
print_r(json_decode($data,true));
} catch(FacebookApiException $e){
echo "Error:" . print_r($e, true);
}
}
?>
提前致谢