Flickr API を使ってみよう


PHPのserialize, unserializeを使ったサンプルである。

1.API Key取得以下のところでAPI Keyを取得。(入力項目は適当に)

2. PHPからリクエスト発行
サンプルの ‘api_key’ の部分は1で取得したキーを使用。

  //API パラメータ
  $params = array('api_key' => '**************',
          'method' => '',
          'user_id' => '9823188@N07',
          'format' => 'php_serial',);
  $encoded_params = array();

  foreach ($params as $k => $v){
    $encoded_params[] = urlencode($k).'='.urlencode($v);

  //API リクエスト
  $url = "".
                      implode('&', $encoded_params);
  $rsp = file_get_contents($url);
  $rsp_obj = unserialize($rsp);

  //API レスポンス
  if ($rsp_obj['stat'] == 'ok'){
    foreach ($rsp_obj['photos']['photo'] as $photo){
      $farm_id = $photo['farm'];
      $server_id = $photo['server'];
      $id = $photo['id'];
      $secret = $photo['secret'];
      echo "<img src='http://farm".$farm_id.".
      echo $server_id."/".$id."_".$secret."_s.jpg'/>";
    echo "呼び出し失敗!";



6 thoughts on “Flickr API を使ってみよう

  1. いや〜、たすかりました!

  2. On 16 May 2006, Flickr updated its services from beta to “gamma”, along with a design and structural overhaul. According to the site’s FAQ, the term “gamma”, rarely used in software development, is intended to be tongue-in-cheek to indicate that the service is always being tested by its users, and is in a state of perpetual improvement…*

    Keep it up

  3. 探し回ってもエラーがでるスクリプトばかり、JavaScriptばかりでしたので、PHPのこちらのスクリプトはとても救いとなりました!ありがとうございました!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s