如何将照片上传到粉丝的个人资料?

时间:2012-03-03 10:12:30

标签: facebook upload

1 个答案:

答案 0 :(得分:0)

您的示例代码

<?php
          // Remember to copy files from the SDK's src/ directory to a
          // directory in your application on the server, such as php-sdk/
          require_once('src/facebook.php');
        $config=array();
        $config['appid']='****';
        $config['secret']='*********';
        $config['appurl']='http://apps.facebook.com/YOUR APP/';
          $configsdk = array(
            'appId' => $config['appid'],
            'secret' => $config['secret'],
            'fileUpload' => TRUE, // optional
          );

          $facebook = new Facebook($configsdk);
          $user_id = $facebook->getUser();

        if(empty($user_id)){
            $dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" 
               . $GLOBALS['config']['appid'] . "&redirect_uri=" . urlencode($config['appurl']).'&scope=publish_stream';
            echo ("<script> top.location.href='".$dialog_url ."' </script>");
            break;
        }
              // We have a user ID, so probably a logged in user.
              // If not, we'll get an exception, which we handle below.
              try {
                $user=$facebook->api('me','GET');
              } catch(FacebookApiException $e) {
                error_log($e->getType());
                error_log($e->getMessage());
              }  
        $src['0']='http://techsinter.com/apps/picbackg.jpg';
        $iTmp2 = imagecreatefromjpeg($src['0']);
        $iOut = imagecreatetruecolor ("740","680") ;
        @imagecopy ($iOut,$iTmp2,0,0,0,0,imagesx($iTmp2),imagesy($iTmp2));
        @imagedestroy ($iTmp2); 
        $white = imagecolorallocate($iOut, 0xFF, 0xFF, 0xFF);
        // Path to our ttf font file
        $font_file = './arial.ttf';
        // Draw the text 'PHP Manual' using font size 13
        $photo=time().'.png';
        imagefttext($iOut, 13, 0, 300, 40, $white, $font_file, $user['name']);
        imagepng($iOut,$photo);
     $ret_obj = $facebook->api('/me/photos', 'POST', array(
                                         'source' => '@' . $photo,
                                         'message' => 'Hello',
                                         )
                                      );
    unlink($photo);
      ?>

该应用程序正在获得用户发布和发布的权限。获得此权限后,从页面上传照片就像从应用上传照片一样 首先,您必须从api合并用户的名称&amp;获取用户名。一张照片 将其上传到用户个人资料请点击此处:

将照片上传到用户的个人资料

https://developers.facebook.com/docs/reference/php/facebook-api/