首先要申請 API

說明使用 PHP 透過 flickr API 抓取使用者相簿的內容(flickr.photosets.getPhotos)的方法。

可以傳入的參數有這些:

api_key (必需的)
Your API application key. See here for more details.
photoset_id (必需的)
The id of the photoset to return the photos for.
user_id (必需的)
The user_id here is the owner of the set passed in photoset_id.
extras (可選的)
A comma-delimited list of extra information to fetch for each returned record. Currently supported fields are: license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_m, url_o
per_page (可選的)
Number of photos to return per page. If this argument is omitted, it defaults to 500. The maximum allowed value is 500.
page (可選的)
The page of results to return. If this argument is omitted, it defaults to 1.
privacy_filter (可選的)
Return photos only matching a certain privacy level. This only applies when making an authenticated call to view a photoset you own. Valid values are:
  • 1 public photos
  • 2 private photos visible to friends
  • 3 private photos visible to family
  • 4 private photos visible to friends & family
  • 5 completely private photos
media (可選的)
Filter results by media type. Possible values are all (default), photos or videos

 

帶到 php:

$params = array(
            'api_key'	=> YOUR_API_KEY,
            'method'	=> 'flickr.photosets.getPhotos',
            'photoset_id'=> PHOTOSET_ID,
            'user_id'	=> FLICKR_USER_ID
            'page'=> PAGE,  //第幾頁
            'per_page'=>500, //預設 500
            'format'	=> 'php_serial'
);
$encoded_params = array();

foreach ($params as $k => $v){
            $encoded_params[] = urlencode($k).'='.urlencode($v);
}
$url = "https://api.flickr.com/services/rest/?".implode('&', $encoded_params);

$rsp = file_get_contents($url);
$rsp_obj = unserialize($rsp);

抓到後再處理物件就好了。

 

API 說明
flickr.photosets.getPhotos