2012-02-23 139 views
0
<?php 

require_once 'facebook.php'; 
require_once 'config.php'; 

error_reporting(0); 

if (isset($_GET['code'])){ 
    header("Location: http://apps.facebook.com/your_perfect_couple/"); 
    exit; 
} 

$fb = new Facebook(array(
       'appId' => $appid, 
       'secret' => $appsecret, 
       'cookie' => true, 
           'fileUpload' => true 
)); 

$me = null; 

$user = $fb->getUser(); 

if($user) { 
    try { 

      $me = $fb->api('/me'); 
    } catch(FacebookApiException $e) { 
      error_log($e); 
    } 
} 

$permsneeded='publish_stream,user_photos,photo_upload'; 

if ($me){} 
else { 
    $loginUrl = $fb->getLoginUrl(array(
       'scope' => $permsneeded, 
       )); 

    echo " 
     <script type='text/javascript'> 
     window.top.location.href = '$loginUrl'; 
     </script> 
    "; 

    exit; 
} 

if(isset($_GET['signed_request'])) { 
    $fb_args="signed_request=". $_REQUEST 
    ['signed_request']; } 

//we start 

$appname=$me[name]; 
        $appid=$me[id]; 

echo "<h1>Whom Can You Make a Perfect Couple With?</h1></br></br>"; 
$appname_user = $appname; 

try { 
$friends = $fb->api('/me/friends?fields=picture,name,id'); 
}catch(FacebookApiException $e) { 
      error_log($e); 
    } 
$num_friends = count($friends[data]); 
$selected_friend= mt_rand(1,$num_friends); 

$f_name= $friends[data][$selected_friend][name]; 
$f_id = $friends[data][$selected_friend][id]; 
$appname_frnd=$f_name; 



      $base = imagecreatefromjpeg('base.jpg'); 
      $white = ImageColorAllocate($base, 100,130,255); 


        $font = 'ARIAL.TTF'; 
        $font2='Cacophony Loud.ttf'; 
        imagettftext($base, 50, 0, 30, 90, $white, $font2, $appname_user); 
        imagettftext($base, 50, 0, 80, 260, $white, $font2, $appname_frnd); 

        // Output and free memory 
        // header('Content-type: image/jpg'); 


        $image="final/final_".$appid.".jpg"; 


        imagejpeg($base,$image); 
        echo "<img src='$image' />"; 



//We end 
//upload image 


    $message = 'Wohh, I cant believe , I Can make a Perfect Couple With '.$appname_frnd.' :P http://apps.facebook.com/your_perfect_couple/ '; 


     try { 


     $ret_obj = $fb->api('/me/photos', 'POST', array(
             'source' => '@' . $image, 
             'message' => $message, 
             ) 
            ); 


     } catch(FacebookApiException $e) { 

     $login_url = $fb->getLoginUrl(array(
         'scope' => 'photo_upload' 
         )); 
     echo 'Please <a href="' . $login_url . '">login.</a>'; 
     error_log($e->getType()); 
     error_log($e->getMessage()); 
     } 


?> 

我在做這上傳形成的圖像Facebook應用程序... 一切都很酷.. ,但我沒有得到任何東西來標記randon人,我附上名稱圖像...如何標記好友在Facebook上的照片上傳通過圖形API一個照片

只是告訴我如何標記的照片:)

請告訴我如何做到這一點在此代碼:)

+0

我上次檢查時間爲2012年1月?標記照片(圖通過上傳),通過圖形API – scibuff 2012-02-23 12:48:33

+0

沒有工作,那麼我們如何能做到這一點:( 難道光是有沒有辦法做到這一點 – 2012-02-23 12:58:24

+0

可能這會爲你 - HTTP工作:/ /stackoverflow.com/questions/6225009/tagging-photos-via-facebook-graphapi – 2012-02-23 14:08:51

回答