如何在 Facebook 照片上标记朋友 通过 Graph API 上传照片

发布于 2025-01-08 14:32:55 字数 3166 浏览 4 评论 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 应用程序,上传形成的图像.. 一切都很酷.. 但我没有得到任何东西来标记随机的人,我正在将该名称附加到该图像上...

只需告诉我如何在照片上标记一个人:)

请告诉我如何在此代码中执行此操作:)

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


?>

I am making facebook application which uploads the image formed ..
everything is cool ..
but i am not getting anything to tag the randon person, i am attaching the name on that image ...

just tell me how to tag a person on a photo :)

please tell me how to do this in this code :)

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

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

发布评论

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

评论(2

薄荷梦 2025-01-15 14:32:55

是的,我很确定这不起作用,你只是一种“无效内容”或类似的错误;除非图形 API 已更新,否则无法通过 API 添加照片标签。您唯一能做的就是上传图像,添加“标签”按钮并将用户重定向到 Facebook 上的图像,在那里他们可以手动标记它,例如这里:http://o2-academy.vccphub.com/snapbooth.php/snapbooth/image/2012-01-21-032244-o2ac1-1740164044-8972579

yeah, I'm pretty sure that doesn't work, you just a sort of "invalid content" or similar error; Unless there has been an update to graph API is it NOT possible to add photo tags via the API. The only thing you can do is upload the image, add a "tag" button and redirect the user to the image on Facebook where they can tag it manually, such as here: http://o2-academy.vccphub.com/snapbooth.php/snapbooth/image/2012-01-21-032244-o2ac1-1740164044-8972579

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