2013-11-21 41 views
0

你好傢伙我試圖瞭解如何從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"; 
       } 

      ?> 

回答

0

您將需要得到從照片表中的SRC或src_big場,然後下載此使用curl,file_put_contents或相似。有不少的StackOverflow的答案對抓取的圖像,並將其保存到一個文件 - 如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

相關問題