How to import photos from Facebook?

后端 未结 5 1420
渐次进展
渐次进展 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 07:09

    Sure you can retrieve photos from users that have added you application and agreed to share such information. First you retrieve the albums using the photos_getAlbums API call, then you can loop over album ids and call photos_get to retrieve photos for the albums.

      /**
       * get_albums()
       *
       * @param long $uid
       * @return array
       */
        function get_albums($uid=null)
        {
             if (empty($uid))
                $uid = $_REQUEST['fb_sig_user'];
            try
            {
                return $facebook->api_client->photos_getAlbums($uid,null);
            }
            catch (FacebookRestClientException $ex)
    { return array(); } }

    /** * get_photos() * * @param bool $bool_pids * @param mixed $aids (array of album ids or null) * @return array */ function get_photos($bool_pids=true, $aids=null, $pids=null) { try {
    $p = $facebook->api_client->photos_get(null, $aids, $pids); } catch (FacebookRestClientException $ex)
    { }

        if ($bool_pids)
        {
            $pids = array();
            if (!empty($p))
            foreach($p as $p0)
                $pids[] = $p0['pid'];
            return $pids;
        }
        else
            return $p;
    }
    

提交回复
热议问题