如何在上传应用创建的图片时标记多个用户? Facebook / PHP / Graph API

时间:2011-08-19 12:35:02

标签: php facebook facebook-graph-api photo

本守则运作良好:

$str1=$userid.'.jpg';
$facebook->setFileUploadSupport(true); 
$data0 = array('tag_uid' => $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                             
    ));

但是当我添加这两行时,标记将不再起作用:

...
$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'];
...

我有publish_stream,user_photos,user_photo_video_tags权限。 任何想法为什么或如何解决问题?

谢谢!

3 个答案:

答案 0 :(得分:1)

$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;
}

答案 1 :(得分:0)

找不到其他解决方案,只是逐个标记每个用户。上传中的第一个就像在第一个代码段中一样,然后是:

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);
    }
}

非常感谢,@ ifaour

答案 2 :(得分:0)

我能够使用Javascript一次添加多个标签来向图形api发出请求,我认为你可以使用同样的方法处理你的答案,只需在调用file_get_contents之前将json对象添加到url。我使用的代码如下:

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) {                

        }                            
    });