dqw70970 2011-05-18 11:11
浏览 44
已采纳

从php脚本中检索Facebook照片

I want to develop an app in php that I can link with a particular photo album in my Facebook profile (or with all my photos) in order to know the direct url link of each photo.

The idea is to make an php script who shows in chronological order my facebook photos like a presentation. Im php programmer, but I know nothing about Facebook integration API. So guys if you can suggest me ways to do this it will be nice. Sorry for my English. Thanks!

  • 写回答

1条回答 默认 最新

  • dongxixia6399 2011-05-18 11:13
    关注

    here is a class for retriving specific user profile pictures (PHP), you'll get the idea from it to create what you want:

    <?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
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。