how to tag random friend upload picture

I wanted to know how I tagged random friends when I bring up an image with this code This code opens an album and uploads an image.

If someone here can help me what to change, and add code"

Thank you

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

?>

Answers


According documentation i added code to you script

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

Just implement function "getRandomFriends()" that returns list of UID's.


Need Your Help

UWP Print preview not updating after window resize

uwp

I'm currently developing an UWP app and using the Windows.Graphics.Printing.PrintManager class to show the preview window. I have some controls which affect the result and I call printDocument.

Getting Data to Show up in My view

asp.net-mvc view model asp.net-mvc-5

I've got a model and controller that is working, but my model is not showing any data inside the view. Any ideas on what I am doing wrong?