I have a facebook photo tagging app that used to work a few months ago but no longer does. The user authenticates the app and it uploads a picture on their facebook account and tags their friends. The app uploads the picture but stopped tagging for some reason.
require_once('facebook.php');
$_SESSION['init'] = true; $current_date=date('m/d/Y'); $facebook =
new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true,
));
$facebook->setFileUploadSupport(true);
$session = $facebook->getSession(); $tokenorig =
$facebook->getAccessToken();
$friends =
file_get_contents("https://graph.facebook.com/me/friends?access_token="
. $tokenorig);
$friends = json_decode($friends, true);
$friends = $friends['data'];
foreach($friends as $friend) {
$uids[] = $friend['id'];
}
function makeTagArray($userId) {
$x=1; $y=1;
foreach($userId as $id) {
$tags[] = array('tag_uid'=>$id, 'x'=开发者_JS百科>$x,'y'=>$y);
$x+=1;
$y+=1;
}
$tags = json_encode($tags);
return $tags;
}
$arguments = array(
'message' => 'hi guys ',
'tags' => makeTagArray($uids),
'source' => '@' .realpath('pic2.jpg'),
);
$alb = "13378";
uploadPhoto(
$facebook,
$alb,
$arguments,
$tokenorig);
function uploadPhoto($facebook,$albId,$arguments,$tokenorig) {
//https://graph.facebook.com/me/photos
try {
$fbUpload =
$facebook->api('/'.$albId.'/photos?access_token='.$tokenorig,'post',
$arguments);
return $fbUpload;
} catch(FacebookApiException $e) {
echo "eror";
echo $e;
// var_dump($e);
return false;
}
}
//////////end
First off all, You need user's to authorize your application to upload photos and tag on behalf of them and you need publish_stream and user_photos permissions to tag user's friends
精彩评论