上传的照片通过我的服务器上的fql查询

问题描述:

你好家伙我试图了解如何从Facebook上传图片。上传的照片通过我的服务器上的fql查询

函数用于执行fql查询。对未来的场合很有用。

<?php 
     // connection facebook api key... 
     function fb_fql($fql) { 
       $this->ci =& get_instance(); 
      // Get User Details 
      $this->ci->load->model('facebook_model'); 
      $this->ci->load->library('user'); 



      // $fb_id = $this->ci->user->get_facebook_id($this->ci->session->userdata('user_id')); 
      // User is found 

       // Get Facebook User profile 
       $user_profile = $this->ci->facebook->getUser(); 
       $result = false; 
        if ($user_profile) { // if profile exist 
         try{ 

          $accessToken = $this->ci->facebook->getAccessToken(); 
          $fb_id = $this->ci->facebook->api('/me?access_token='.$accessToken); 
          if(isset($user_profile)) 
          { 
          $fql_run = array(
           'method' => 'fql.query', 
           'query' => $fql, 
          ); 
          $result = $this->ci->facebook->api($fql_run); // run fql 
          } else { $result = false; } 
         }catch(FacebookApiException $e){ 
          $result = null; 
         }  

        } 
        return $result; 

     } 

?> 

在这里,我通过此查询得到的照片和数组的结果显示正确的facebook照片10张。现在我必须将其上传到我的服务器上,但我该怎么做?

<?php 
       // fql query 
       $fql = "SELECT pid 
        FROM photo 
        WHERE aid IN (
         SELECT aid 
         FROM album 
         WHERE owner=me() LIMIT 10 
       ) "; 
       // run query 
       $photos = $this->facebook_action->fb_fql($fql); 
       if ($photos != false) { 
        foreach ($photos as $photo) { 
         echo print_r($photos); // show the array with the data taken 
         // here i would like upload the photos got from the query. 
        } 
       } else { 
        echo "no photo"; 
       } 

      ?> 

您将需要得到从照片表中的SRC或src_big场,然后下载此使用curl,file_put_contents或相似。有不少的*的答案对抓取的图像,并将其保存到一个文件 - 如Saving image from PHP URL

SELECT src_big FROM photo 
WHERE aid IN (SELECT aid FROM album WHERE owner=me() LIMIT 10) 

因为要下载用户数据到自己的服务器,我建议你检查你的应用程序不违反Facebook Platform Policy