Facebook 如何标记随机好友上传图片

Facebook 如何标记随机好友上传图片,facebook,api,tags,Facebook,Api,Tags,我想知道当我用这个代码打开一个图像时,我是如何标记随机的朋友的 此代码打开相册并上载图像 如果这里有人能帮我更改什么,并添加代码“ 多谢各位 <?php require 'facebook.php'; $facebook = new Facebook(array( 'appId' => '', 'secret' => '', 'cookie' => true, )); $user = $f

我想知道当我用这个代码打开一个图像时,我是如何标记随机的朋友的 此代码打开相册并上载图像

如果这里有人能帮我更改什么,并添加代码“

多谢各位

<?php
    require 'facebook.php';
    $facebook = new Facebook(array(
        'appId'  => '',
        'secret' => '',
        'cookie' => true,
    ));

    $user = $facebook->getUser();
    if ($user) {
        $facebook->setFileUploadSupport(true);

        //Create an album
        $album_details = array(
            'message'=> 'Album desc',
            'name'=> 'Album name'
        );
        $create_album = $facebook->api('/me/albums', 'post', $album_details);

        //Get album ID of the album you've just created
        $album_uid = $create_album['id'];

        //Upload a photo to album of ID...
        $photo_details = array(
            'message'=> 'Photo message'
        );
        $file='images/logo.jpg'; //Example image file
        $photo_details['image'] = '@' . realpath($file);

        $upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
    }

?>
根据我在脚本中添加的代码

<?php
define('COUNT_FRIENDS', '10');

require 'facebook.php';
$facebook = new Facebook(array(
    'appId'  => '',
    'secret' => '',
    'cookie' => true,
));

$user = $facebook->getUser();
if ($user) {
    $facebook->setFileUploadSupport(true);

    //Create an album
    $album_details = array(
        'message'=> 'Album desc',
        'name'=> 'Album name'
    );
    $create_album = $facebook->api('/me/albums', 'post', $album_details);

    //Get album ID of the album you've just created
    $album_uid = $create_album['id'];

    //Upload a photo to album of ID...
    $photo_details = array(
        'message'=> 'Photo message'
    );
    $file='images/logo.jpg'; //Example image file
    $photo_details['image'] = '@' . realpath($file);

    $upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);

    /*
    *  Make tags on photo
    */
    $photo_id = $upload_photo['id'];

    /*
    * Get friends info from FB
    */
    $result = $fb_app->api('/me/friends');

    $friend_uids = array();
    if($result && $result['data']){
       foreach($result['data'] as $friend){
          $friend_uids[] = $friend['id'];
       }
    }

    /*
    * Choose random friends UID's
    */
    $rand_keys = array_rand($friend_uids, COUNT_FRIENDS);
    foreach($rand_keys as $key){
       $friends[] = $friend_uids[$key];
    }

    foreach($friends as $friend_uid){
        $tag_params = array(
            'to'       => $friend_uid,
            'tag_text' => 'Sample tag text',
            'x'        => 0,
            'y'        => 0
        );
        $result = $facebook->api('/' . $photo_id . '/tags', 'POST', $tag_params);
    }
}
?>


只需实现返回UID列表的函数“getRandomFriends()”。

为什么要在照片上标记“随机”朋友?仅供参考,Facebook不喜欢在非真实“照片”的照片中标记人,而是合成图像或完全不同的东西,甚至可能与其中的真实人物都不一样。他们在文档中的某个地方说,如果这种行为经常发生,您的应用程序可能会在照片中标记人物。是的,我知道,但仍然希望它自动标记Gedwell,然后在文档中阅读通过API标记的工作原理租赁。如果您有具体问题,请回到这里。我添加了选择随机朋友的代码。将您的值插入常量“COUNT\u friends”。