开发者

How can I tag several users when uploading an app created image? Facebook/PHP/Graph API

开发者 https://www.devze.com 2023-03-29 01:18 出处:网络
This Code works fine: $str1=$userid.\'.jpg\'; $facebook->setFileUploadSupport(true); $data0 = array(\'tag_uid\' =>开发者_如何学JAVA; $bild1[1],\'x\' => rand() % 100,\'y\' => rand() % 100)

This Code works fine:

$str1=$userid.'.jpg';
$facebook->setFileUploadSupport(true); 
$data0 = array('tag_uid' =>开发者_如何学JAVA; $bild1[1],'x' => rand() % 100,'y' => rand() % 100);
$datatags[] = json_encode($data0);
$access_token = $session['access_token'];
$result = $facebook->api('/me/photos', 'post', array(
    'source' => '@'.realpath($str1),
    'access_token' => $access_token,
    'message' => 'My Hottest Friends',
    'tags' => $datatags                             
    ));

But the tagging will not work anymore, when I add these two lines:

...
$datatags[] = json_encode($data0);
$data1 = array('tag_uid' => $bild1[2],'x' => rand() % 100,'y' => rand() % 100);
$datatags[] = json_encode($data1);
$access_token = $session['access_token'];
...

I have the publish_stream,user_photos,user_photo_video_tags permissions. Any ideas why or how to solve the problem?

Thank you!


$str1=$userid.'.jpg';
$facebook->setFileUploadSupport(true); 
$friends_tag_array[]=array('uid'=>'xxxx1','x'=>'xxxx','y'=>'xxxx');
$friends_tag_array[]=array('uid'=>'xxxx2','x'=>'xxxx','y'=>'xxxx');
$datatags=getTag($friends_tag_array); 
$access_token = $session['access_token'];

$result = $facebook->api('/me/photos', 'post', array(
    'source' => '@'.realpath($str1),
    'access_token' => $access_token,
    'message' => 'My Hottest Friends',
    'tags' => $datatags                             
    ));

function getTag($friends_tag_array){
    for($i=0 ;$i<count($friends_tag_array);$i++){
    $tag = array('tag_uid' => $friends_tag_array[$i]['uid'],'x' =>$friends_uid_array[$i]['x'],'y' =>$friends_uid_array['y']);
    $tag_data[]=$tag;
   }
   return $tag_data;
}


Found no other solution but to tag each user one by one. First one in the upload like in the first code snippet and then:

for ($i=2; $i<10; $i++) {
    if ($bild1[$i]) {
        $y=($i*10)-5;
        $post_url = "https://graph.facebook.com/".$result[id]."/tags/". $bild1[$i]."?access_token=".$access_token."&x=20&y=".$y."&method=POST";
        $response = file_get_contents($post_url);
    }
}

Thank you very much, @ifaour


I was able to add multiple tags at once using Javascript to make a request to the graph api, I would assume you could make the same thing work with your answer, just add the json object to the url before calling file_get_contents. The code I used is below:

var arrTags = [];

for(var i = 0; i< ns.numTags; i++){
            var tag = {
                tag_uid: ns.Dictionary['FBTags'][i].to,
                x: ns.Dictionary['FBTags'][i].x,
                y: ns.Dictionary['FBTags'][i].y
            };

            arrTags.push(tag);
        }

Ext.Ajax.request({
        url: 'https://graph.facebook.com/' + ns.Dictionary['FBImageId'] + '/tags?tags='+JSON.stringify(arrTags),
        method: 'POST',
        params: {
            access_token: ns.Dictionary['FBAccessToken']
        },
        headers: {

        },
        success: function(response, originalCall) {                

        }                            
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消