从php脚本中检索Facebook照片

问题描述:

我想在php中开发一个应用程序,以便我可以链接到我的Facebook个人资料(或所有照片)中的特定相册,以便了解每张照片的直接链接。从php脚本中检索Facebook照片

这个想法是让一个PHP脚本谁按照时间顺序显示我的Facebook像一个演示文稿的照片。我的PHP程序员,但我对Facebook集成API一无所知。所以,如果你能建议我这样做的话,那会很好。对不起我的英语不好。谢谢!

这里是retriving特定用户的个人资料照片(PHP),你会从它那里得到的想法,创造你想要的一类:

<?php 

class FBPicture { 
    public $uid; 
    public $dir; 
    public $type = 'large'; 

    public function setUId ($id) { 
     $this->uid = $id; 
    } 

    public function setDir ($dir) { 
     $this->dir = $dir; 
    } 

    public function fetch ($_uid=null, $_dir=null, $_type=null) { 
     if ($_uid === null) 
      throw new CHttpException ('Facebook User ID or Username is not set.'); 
     if ($_dir === null) 
      $_dir = '/storage/'; 
     if ($_type === null) 
      $_type = 'large'; 

     $this->uid = $_uid; 
     $this->dir = $_dir; 
     $this->type = $_type; 

     $dir = getcwd() . $this->dir; 
     $type = $this->type; 

     // request URI 
     $host = 'http://graph.facebook.com/' . $_uid; 
     $request = '/picture'; 
     $type = '?type=' . $type; 

     $contents = file_get_contents ($host.$request.$type); 

     // create the file (check existance); 
     $file = 'fb_' . $uid . '_' . rand (0, 9999); 
     $ext = '.jpg'; 

     if (file_exists ($dir)) { 
      if (file_exists ($dir.$file.$ext)) { 
       $file .= $dir.$file.'2'.$ext; 

       if ($this->appendToFile ($file, $contents)) { 
        return str_replace ($dir, '', $file); 
       } 
      } else { 
       $file = $dir.$file.$ext; 
       touch ($file); 

       if ($this->appendToFile ($file, $contents)) { 
        return str_replace ($dir, '', $file); 
       } 
      } 
     } else { 
      // false is returned if directory doesn't exist 
      return false; 
     } 
    } 

    private function appendToFile ($file, $contents) { 
     $fp = fopen ($file, 'w'); 
     $retVal = fwrite ($fp, $contents); 
     fclose ($fp); 

     return $retVal; 
    } 
} 

// sample usage: 
// $pic will be the filename of the saved file... 
$pic = FBPicture::fetch('zuck', 'uploads/', 'large'); // get a large photo of Mark Zuckerberg, and save it in the "uploads/" directory 
// this will request the graph url: http://graph.facebook.com/zuck/picture?type=large 

?>