上传应用程序创建的图像时如何标记多个用户? Facebook/PHP/图形 API

发布于 2024-11-30 13:28:49 字数 873 浏览 0 评论 0原文

这段代码工作正常:

$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权限。 有什么想法或者如何解决这个问题吗?

谢谢你!

This Code works fine:

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

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无名指的心愿 2024-12-07 13:28:49
$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;
}
$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;
}
童话 2024-12-07 13:28:49

除了一一标记每个用户之外,没有找到其他解决方案。上传中的第一个,如第一个代码片段,然后:

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

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

秋千易 2024-12-07 13:28:49

我能够使用 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) {                

        }                            
    });

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

        }                            
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文