How to import photos from Facebook?

后端 未结 5 1424
渐次进展
渐次进展 2021-01-13 06:33

I noticed when I visit photo printing websites, they ask you if you would like to import your photos from Facebook. How do they do it? Does Facebook provide API to import us

5条回答
  •  广开言路
    2021-01-13 06:47

    get_albums returns an array of albums, do a var_dump to see what it returns.

    
    $albums = get_albums($facebook);
    foreach($albums as $album)
    {
         if($album["count"] > 0)
         {
              //if the album has pictures, then do something with the album
         }
    }
    
    function get_albums($facebook)
    {
        $fb_user = getFbUser($facebook);
        $myalbums = $facebook->api('/me/albums');
        return $myalbums["data"];
    }
    
    function getFbUser($facebook)
    {
        $fb_user = $facebook->getUser(); //gets user id
    
        if(is_null($fb_user))
        {
                header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos'))}");
                exit;
        }
        return $fb_user;
    }
    
    function getFb()
    {
        $facebook = new Facebook(array(
            'appId' => 'your_appid',
            'secret' => 'your_secret',
            'cookie' => true,
            ));
        return $facebook;
    }
    

    See: http://www.joeyrivera.com/2010/facebook-graph-api-app-easy-w-php-sdk/

提交回复
热议问题