• 締切済み

Flickrの写真に対するコメント取得

Flickrに投稿された写真のコメントをAPIを使って取得しようと考えています。 写真の取得はこのサイトを参考にしてできましたが、コメントの取得がうまくいきません。 コードはこのサイトに書いてある通りで変えていませんが、どの部分を変更すればうまくコメント取得はできるのでしょうか。 検索結果をJSONに変換することはできましたが、コメントを画面に出力することができません。 わかるかたお願いします。 コードはここに載せておきます。 <?php //ライブラリを読み込む require_once 'phpflickr-master/phpFlickr.php' ; // Consumer Key $app_key = '' ; // Consumer Secret $app_secret = '' ; // インスタンスを作成する $flickr = new phpFlickr( $app_key , $app_secret ) ; //オプションの設定 $option = array( 'tags' => 'Tokyo, Japan', 'per_page' => 50 , // 取得件数 'extras' => 'description' , // 画像サイズ 'safe_search' => 3 , // セーフサーチ 'sort' => 'interestingness-desc', ) ; // GETメソッドで指定がある場合 foreach( array( 'tag' , 'per_page' , 'woe_id' , 'license' , 'sort' , 'bbox' ) as $val ) { if( isset( $_GET[ $val ] ) && $_GET[ $val ] != '' ) { $option[ $val ] = $_GET[ $val ] ; } } // 検索を実行し、取得したデータを[$result]に代入する $result = $flickr->photos_search( $option ) ; // [$result]をJSONに変換する $json = json_encode( $result ); // JSONをオブジェクト型に変換する $obj = json_decode( $json ) ; // HTML用 $html = '' ; // 写真検索を実行する $html .= '<h2>条件を指定する</h2>' ; $html .= '<p>条件を指定して、写真を検索してみて下さい。</p>' ; $html .= '<form>' ; $html .= '<p style="font-size:.9em; font-weight:700;"><label for="text">検索キーワード (text)</label></p>' ; $html .= '<p style="margin:0 0 1em;"><input id="text" name="text" value="寺" placeholder="寺"></p>' ; $html .= '<p style="font-size:.9em; font-weight:700;"><label for="bbox">位置範囲 (bbox)</label></p>' ; $html .= '<p style="margin:0 0 1em;"><input id="bbox" name="bbox" list="bbox-data" placeholder=""></p>' ; $html .= '<datalist id="bbox-data">' ; $html .= '<option value="139.74136476171873,35.67800739824976,139.78565339697263,35.71146639304908">' ; $html .= '</datalist>' ; $html .= '<p><button>検索する</button></p>' ; $html .= '</form>' ; // 実行結果の表示 $html .= '<h2>実行結果</h2>' ; $html .= '<p>リクエストの実行結果です。</p>' ; // リスト形式で表示する $html .= '<ul style="margin:2em 0 0; padding:0; overflow:hidden; list-style-type:none; text-align:center;">' ; // ループ処理 foreach( $obj->photo as $photo ) { // データが揃っていない場合はスキップ if( !isset($photo->url_q) || !isset($photo->width_q) || !isset($photo->height_q) ) { continue ; } // データの整理 $t_src = $photo->url_q ; // サムネイルの画像ファイルのURL $t_width = $photo->width_q ; // サムネイルの横幅 $t_height = $photo->height_q ; // サムネイルの縦幅 $o_src = ( isset($photo->url_c) ) ? $photo->url_c : $photo->url_q ; // 画像ファイルのURL // 出力する $html .= '<li style="float:left; margin:1px; padding:0; overflow:hidden; height:112.5px">' ; $html .= '<a href="' . $o_src . '" target="_blank">' ; $html .= '<img src="' . $t_src . '" width="' . $t_width . '" height="' . $t_height . '" style="max-width:100%; height:auto">' ; $html .= '</a>' ; $html .= '</li>' ; } $html .= '</ul>' ; // 取得したデータ $html .= '<h2>取得したデータ</h2>' ; $html .= '<p>下記のデータを取得できました。</p>' ; $html .= '<h3>JSONに変換後</h3>' ; $html .= '<p><textarea rows="8">' . $json . '</textarea></p>' ; ?><!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="robots" content="noindex,nofollow"> <link rel="stylesheet" type="text/css" href="style.css"> <!-- ビューポートの設定 --> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Flickr APIで写真を検索するサンプルデモ</title> </head> <body> <div id="main"> <p>aaa</p> </div> <div id="main2"> <?php echo $html ?> <p style="text-align:center"><a href="https://syncer.jp/flickr-api-matome">配布元: Syncer</a></p> </div> </body> </html>

  • PHP
  • 回答数1
  • ありがとう数0

みんなの回答

  • shimix
  • ベストアンサー率54% (865/1590)
回答No.1

>'extras' => 'description' , // 画像サイズ descriptionがコメントだったと思いますが・・・。extras に description を指定していれば、$photo->description で取得出来ませんか? >foreach( $obj->photo as $photo ) の前に、 echo "<pre>"; var_dump($obj); echo "</pre>"; とでも入れて、取得内容を確認してみてください。

関連するQ&A

  • flickrでの画像を取得について

    次の関数はflickr.interesting.getListでflickrから人気の高い画像を取得する関数ですが、パラメータのdateを指定すると Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\flickr-interesting.php on line 34 と表示されます。 date => 2013-07-24,の行を消すと画像が正常に表示されます。 dateを指定するにはどうすればいいでしょうか? function search_photos($per_page, $page) { $proxy = array( "http" => array( "proxy" => "tcp://大学のIPアドレス", 'request_fulluri' => true, ), ); $proxy_context = stream_context_create($proxy); $params = array( 'method' => 'flickr.interestingness.getList', 'api_key' => API_KEY, 'date' => 2013-07-24, 'per_page' => $per_page, 'page' => $page ); $pictureSize = "b"; $query = http_build_query($params, '', '&'); $url = 'http://www.flickr.com/services/rest/?' . $query; //$data = @simplexml_load_string(@file_get_contents($url)); $data = @simplexml_load_string(@file_get_contents($url, false, $proxy_context)); if ($data === false) { return 'エラー' . PHP_EOL; } $ret = ''; $format = '<a href="http://www.flickr.com/photos/%s/%s/"><img src="http://farm%s.static.flickr.com/%s/%s_%s_m.jpg" alt="%s"></a>' . PHP_EOL; foreach ($data->photos->photo as $p) { $ret .= sprintf($format, $p['owner'], $p['id'], $p['farm'], $p['server'], $p['id'], $p['secret'], $p['title'], $pictureSize); } return $ret; }

    • ベストアンサー
    • PHP
  • flickrのAPIを用い、任意の写真を表示する方法

    flickrのAPIを用いて、個人のページに、指定した写真を表示させたいと思っています。 こちらのページを、参考にして(そのままのソースで)、flickrにアップロードされた最新の写真の中から、「HDR」というタグが付いた写真は表示させられるようになりました。 http://itpro.nikkeibp.co.jp/article/COLUMN/20061101/252356/?ST=swd-tech これを、写真を“撮影した時の時間”で表示させたいと思っています。 たとえば、2004年1月16日に撮った写真を表示、といった具合です。 flickrは、HPを見ると、taken on~ と写真を撮った時のデータも表示されており、撮影した時間もAPIから取ってこれると思うのですが、以下のソースをどのように変えたらよいでしょうか。 よろしくお願いいたします。 flickr-search.js -------------------------- // 画像検索を行う関数 function photo_search ( param ) { // APIリクエストパラメタの設定 param.api_key = 'APIキー'; param.method = 'flickr.photos.search'; param.per_page = 9; param.sort = 'date-posted-desc'; param.format = 'json'; param.jsoncallback = 'jsonFlickrApi'; // APIリクエストURLの生成(GETメソッド) var url = 'http://www.flickr.com/services/rest/?'+ obj2query( param ); // script 要素の発行 var script = document.createElement( 'script' ); script.type = 'text/javascript'; script.src = url; document.body.appendChild( script ); }; // 現在の表示内容をクリアする function remove_children ( id ) { var div = document.getElementById( id ); while ( div.firstChild ) { div.removeChild( div.lastChild ); } }; // オブジェクトからクエリー文字列を生成する関数 function obj2query ( obj ) { var list = []; for( var key in obj ) { var k = encodeURIComponent(key); var v = encodeURIComponent(obj[key]); list[list.length] = k+'='+v; } var query = list.join( '&' ); return query; } // オブジェクトからクエリー文字列を生成する関数 function obj2query ( obj ) { var list2 = []; for( var key in obj ) { var k = encodeURIComponent(key); var v = encodeURIComponent(obj[key]); list2[list2.length] = k+'='+v; } var query = list2.join( '&' ); return query; } // Flickr検索終了後のコールバック関数 function jsonFlickrApi ( data ) { // データが取得できているかチェック if ( ! data ) return; if ( ! data.photos ) return; var list = data.photos.photo; if ( ! list ) return; if ( ! list.length ) return; // 現在の表示内容(Loading...)をクリアする remove_children( 'photos_here' ); // 各画像を表示する var div = document.getElementById( 'photos_here' ); for( var i=0; i<list.length; i++ ) { var photo = list[i]; // a 要素の生成 var atag = document.createElement( 'a' ); atag.href = 'http://www.flickr.com/photos/'+ photo.owner+'/'+photo.id+'/'; // img 要素の生成 var img = document.createElement( 'img' ); img.src = 'http://static.flickr.com/'+photo.server+ '/'+photo.id+'_'+photo.secret+'_s.jpg'; img.style.border = '0'; atag.appendChild( img ); div.appendChild( atag ); } } search-hdr.html ------------------------------ <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Flickr APIによる画像検索 (text)</title> <script type="text/javascript" src="flickr-search.js"></script> <script type="text/javascript"><!-- window.onload = function () { photo_search({ text: 'HDR' }); } --></script> </head> <body> <hr> <div id="photos_here">Loading...</div> <hr> </body> </html>

  • flickrから画像を取得するプログラムが動かない。

    こんばんわ。 flickrという画像サイトから画像を取得するという方法を試して見たのですが、うまく動きませんでした。何も表示されませんでした。 flickrのキーは取得してあり、キーも、入力した状態です。 レンタルサーバーにて実行しています。 <?php define (APIKEY , "[取得したキー]"); $searchWord = "猫"; //検索したい画像のキーワード $pictureSize = "t"; //画像サイズ $url = "http://www.flickr.com/services/rest/?" . "method=flickr.photos.search" . "&format=rest" . "&api_key=".APIKEY . "&per_page=20" . "&license=1,2,3,4,5,6" . "&extras=owner_name" . "&text=".urlencode($searchWord); $xml = simplexml_load_file($url); //print_r($xml); $iLoop = 0; echo "<table>"; foreach($xml->photos->photo as $photoValue){ if( $iLoop == 0){ echo "<tr><td>"; } else { echo "<td>"; } $farmId = $photoValue['farm']; $serverId = $photoValue['server']; $photoId = $photoValue['id']; $secret = $photoValue['secret']; $owner = $photoValue['owner']; $ownername = $photoValue['ownername']; //改行はレイアウトのため echo "<a href=\"http://www.flickr.com/photos/{$owner}/{$photoId}/\"> <img src=\"http://farm{$farmId}.static.flickr.com/{$serverId}/ {$photoId}_{$secret}_{$pictureSize}.jpg\" /></a><br>"; echo "author by <a href=\"http://www.flickr.com/photos/{$owner}/\"> {$ownername}</a>"; $iLoop++; if( $iLoop == 4){ echo "</td></tr>"; $iLoop = 0; } else { echo "</td>"; } } if( $iLoop != 0 ){ echo "</tr>"; } echo "</table>"; ?> 掲載していたHPはこちら http://webservice.kabufuru.net/flickr/photosPhp.php

    • 締切済み
    • PHP
  • jQuery 2つのsetInterval

    写真と文字を組み合わせたクロスフェードで行き詰りました。 2つ質問があります。 【質問1】 1番目のテキストがフェードイン→3秒待機→1番目のテキストと 1番目の写真がフェードアウト→2番目・3番目同じ→繰り返し。 という感じにしたいのですが、下記の#text-boxの設定ですと setIntervalで5秒間隔でフェードインになるので#photo-boxとの タイミングが5秒ずれてしまいます。 これを合わせるにはどうすればよいのでしょうか? 【質問2】 下記のように、1つのdivでテキストと写真を入れると正常に動かなくなります。 それぞれ分けてdiv(#text-box,#photo-box)で囲うと動きます。 この原因はなんでしょうか? <div id="all-box"> <p class="text">1番目のテキスト</p> <p class="photo"><img src="img/01.jpg" width="500" height="200" alt="" /></p> <p class="text">2番目のテキスト</p> <p class="photo"><img src="img/02.jpg" width="500" height="200" alt="" /></p> <p class="text">3番目のテキスト</p> <p class="photo"><img src="img/03.jpg" width="500" height="200" alt="" /></p> </div> 宜しくお願いします。 $(function(){ $("#text-box .text").hide(); setInterval(function(){ $("#text-box") .find(".text:first-child") .fadeIn(1000) .delay(3000) .fadeOut(1000) .next(".text") .end() .appendTo("#text-box"); },5000); $("#photo-box .photo:gt(0)").hide(); setInterval(function(){ $("#photo-box") .find(".photo:first-child") .fadeOut(1000) .next(".photo") .fadeIn(1000) .end() .appendTo("#photo-box"); },5000); }); ■HTML <div id="all-box"> <div id="text-box"> <p class="text">1番目のテキスト</p> <p class="text">2番目のテキスト</p> <p class="text">3番目のテキスト</p> </div> <div id="photo-box"> <p class="photo"><img src="img/01.jpg" width="500" height="200" alt="" /></p> <p class="photo"><img src="img/02.jpg" width="500" height="200" alt="" /></p> <p class="photo"><img src="img/03.jpg" width="500" height="200" alt="" /></p> </div> </div> ■CSS #all-box{ position:relative; width:500px; height:200px; } #text-box,#photo-box{ width:500px; height:200px; } #text-box .text{ position:absolute; top:80px; left:0; z-index:2; } #photo-box .photo{ position:absolute; top:0; left:0; width:500px; height:200px; z-index:1; }

  • HTML&CSS DIVをぴったりと縦に並べたい

    HTML&CSS初心者です。 下記のソース様に、DIVで一つにまとめたBOXを縦に並べたいのですが、 「見出し002」の上のマージンがうまく取れずに困っています。 .box内のphoto00.jpgをフロートにしている為、フロートが悪さをしている事を考え、 「見出し002」の上のDIV内に<br style="clear: both;" />を入れると、余白が生まれるのですが、 MacのSafariとFirefoxでは、余白の差が出てしまいます。(Safariの方が余白が大きい) <br style="clear: both;" />を入れないと、上のマージンはほぼ消えてしまい、わずかにFirefoxの方では余白が生まれます。 ちなみにこの現象は「ここにテキストが入ります。」の行数を減らすと解決するのですが、 下記のソースでも、photo00.jpgの高さをはみ出す行数ではない為、この<div class="box">に 変な膨らみを持たせたくありません。 どなたか解決法を教えて下さい。よろしくお願い致します。 【HTML】 <div id="main"> <div class="mds01"><h3><em>見出し001</em></h3></div> <div class="box"> <img src="img/photo00.jpg" width="155" height="108"> <h5>小見出し</h5> <p class="txt">ここにテキストが入ります。<br><br> ここにテキストが入ります。<br> ここにテキストが入ります。</p> </div> <div class="box"> <img src="img/photo00.jpg" width="155" height="108"> <h5>小見出し</h5> <p class="txt">ここにテキストが入ります。<br><br> ここにテキストが入ります。<br> ここにテキストが入ります。</p><br style="clear: both;" /> </div> <div class="mds02"><h3><em>見出し002</em></h3></div> <div class="box"> <img src="img/photo00.jpg" width="155" height="108"> <h5>小見出し</h5> <p class="txt">ここにテキストが入ります。<br><br> ここにテキストが入ります。<br> ここにテキストが入ります。</p> </div> </div> 【CSS】 /*メイン大枠部分*/ #main { margin: 0px; padding: 0px; width: 627px; float: right; background: #FFFFFF; height: auto; } /*各見出し*/ .mds01 h3 { background: url(img/mmds01.gif) no-repeat; margin: 25px 0px 15px; padding: 0px; height: 20px; width: 587px; font-size: 9px; color: #FFFFFF; clear: left; float: none; } .mds02 h3 { background: url(img/mmds02.gif) no-repeat; margin: 25px 0px 15px; padding: 0px; height: 20px; width: 587px; font-size: 9px; color: #FFFFFF; clear: left; float: none; } /*ボックス*/ .box { margin: 0px; padding: 0px; height: auto; width: 587px; clear: left; } /*ボックス内・画像とテキスト*/ #main .box img { float: left; padding-right: 10px; } #main .box h5 { font: bold 14px "MS Pゴシック", Osaka; color: #022962; margin: 0px 0px 10px; padding: 0px; } .txt { font: normal 13px/16px "MS Pゴシック", Osaka; color: #333333; margin: 0px; padding: 0px; } em { visibility: hidden; }

    • ベストアンサー
    • HTML
  • text-alignの解除の方法

    text-alignの解除の方法ってありませんか? 例えばhtml内に以下のタグがあるとして、 <div style="text-align:center;"> <div style="width:100px; height:120px; background-image:url(○○○.jpg)"> <div style="width 50px; height: 60px; position:absolute; margin-top: 20px; margin-left:5px"> <p>あいうえおあいうえお</p> </div> </div> </div> このような場合に<div style="width:100px; height:120px; background-image:url(○○○.jpg)">から、対応している</div>のtext-alignを解除する方法ってありませんか? IEの標準には対応するのですが、互換だとブロック要素までもがセンタリングされてしまうため困っています。 分かりづらくて申し訳ありません。

  • CSSファイルのコメント

    CSSファイルにコメント(/*・・・・*/)を入れるとIEで表示されないことがあります。 ftpするとWEB上では表示されるようです。 ローカル環境だけで起こるようなのですが、このような現象後存知ですか? たとえば、CSSの内容は /*ヘダー*/ h1,h2,h3,h4,h5,h6,ul,ol,dl,p { margin-top: 0px; margin-bottom: 0px; } /*内容*/ body { margin: 0px auto; width: 750px; font-size: 0.8em; color: #333333; line-height: 1.5em; 宜しくお願いします。

    • ベストアンサー
    • CSS
  • javascriptでの値の取得について

    すごく素人だと思うのですが。 この手のタイプで得られる値を外部で取得できないのでしょうか? 戻り値で返すわけにもいかないですし、よく理解できていません var val: ○.○=function(){ここで得た値をvalに入れたい} 例1 var target; ・・・ request.onreadystatechange=function(){ if(request.readyState==4 && request.status==200){ //target=request.responseText;みたいなことをしたい } } 例2 var width,height; ・・・ image.onload=function(){ //width=image.width; height=image.height;みたいなことをしたい }

  • HPの行間を広げる line-height が効かないのです。

    お願いします。 cssで行間を変化させるために line-height を書き込んでも、行間がぜんぜん動かないのです。 次のように書きました。 *************************** <style type="text/css"> p{_line-height:_1.7em;_} </style> </head> <body> <p> 行間が変わらない<br> 全然変わらない </p>

  • flickrAPIでの画像取得について

    下のphpスクリプトでflickrAPIを用いて画像を取得しようとしたらエラーが起こって取得できません。 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>flickr API サンプル</title> </head> <body> <h1>flickr API サンプル</h1> <?php set_time_limit(60); //flickrから写真を検索してimgタグを返す関数 function search_flickr($keyword,$limit){ //取得したAPIキーを設定 $api_key = '(僕のAPIキー)'; //メソッドに写真検索を設定 $method = 'flickr.photos.search'; //検索キーワードをURLエンコードして設定 $text = urlencode($keyword); //人気の高い順に検索 $sort = "interestingness-desc"; //取得件数を設定 $per_page = $limit; //URLを生成 $url = 'http://www.flickr.com/services/rest/?'. 'method='.$method. '&api_key='.$api_key. '&text='.$text. '&sort='.$sort. '&per_page='.$per_page; //取得したXMLファイルをパースし、オブジェクトに代入 $data = simplexml_load_file($url) or die("XMLパースエラー"); //表示写真サイズをmサイズに設定 $size = "_m"; //変数初期化 $ret = ""; //取得できた写真の数だけループ処理 foreach($data->photos as $photos){ foreach($photos->photo as $photo){ $ret .= '<a href="http://www.flickr.com/photos/'.$photo['owner'].'/'.$photo['id'].'/">'; $ret .= '<img src="http://farm'.$photo['farm'].'.static.flickr.com/'.$photo['server'].'/'.$photo['id'].'_'.$photo['secret'].$size.'.jpg" alt="'.$photo['title'].'">'."\n"; $ret .= '</a>'; } } return $ret; } //検索ワード $keyword = "sea"; //取得数 $limit = 10; //写真を検索して表示 echo search_flickr($keyword,$limit); ?> <p>powerd by <a href="http://www.flickr.com/services/api/">Flickr Services</a></p> </body> </html> 表示されたページはこうなりました。 flickr API サンプル Warning: simplexml_load_file(http://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=(僕のAPIキー)&text=sea&sort=interestingness-desc&per_page=10): in C:\xampp\htdocs\flickrAPI.php on line 38 Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=(僕のAPIキー)&text=sea&sort=interestingness-desc&per_page=10" in C:\xampp\htdocs\flickrAPI.php on line 38 XMLパースエラー そこでhttp://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=(僕のAPIキー)&text=sea&sort=interestingness-desc&per_page=10にアクセスすると次のようなXMLが表示されました。 <?xml version="1.0" encoding="UTF-8"?> -<rsp stat="ok">-<photos total="9663727" perpage="10" pages="966373" page="1"><photo title="row" isfamily="0" isfriend="0" ispublic="1" farm="1" server="55" secret="86cffac801" owner="89972557@N00" id="148800272"/><photo title="Live" isfamily="0" isfriend="0" ispublic="1" farm="8" server="7381" secret="d5af918c8c" owner="36621592@N06" id="9017742627"/><photo title="In search of the pot of gold at the end of the Rainbow..." isfamily="0" isfriend="0" ispublic="1" farm="4" server="3717" secret="bf47d94889" owner="56936646@N07" id="8851282635"/><photo title="Melting ice 130424 F368" isfamily="0" isfriend="0" ispublic="1" farm="8" server="7404" secret="907a7c260e" owner="44855005@N04" id="8771141696"/><photo title="Coachella Valley" isfamily="0" isfriend="0" ispublic="1" farm="8" server="7310" secret="5d47f6cb45" owner="53760536@N07" id="8729902328"/><photo title="End of a summer day" isfamily="0" isfriend="0" ispublic="1" farm="8" server="7434" secret="46a80bb865" owner="72179079@N00" id="8722395239"/><photo title="angles of sea" isfamily="0" isfriend="0" ispublic="1" farm="9" server="8253" secret="32fc571841" owner="39638504@N07" id="8696358702"/><photo title="Summer sunset ( view larger size: please press "L")" isfamily="0" isfriend="0" ispublic="1" farm="9" server="8261" secret="21c4642b39" owner="72179079@N00" id="8688567245"/><photo title="Smoo Cave II" isfamily="0" isfriend="0" ispublic="1" farm="9" server="8403" secret="b6d637d603" owner="8407953@N03" id="8672345286"/><photo title="In The Middle of Nowhere" isfamily="0" isfriend="0" ispublic="1" farm="9" server="8533" secret="1ba0e8574c" owner="8407953@N03" id="8666924709"/></photos></rsp> どうすればエラーが直るでしょうか?

    • ベストアンサー
    • PHP

専門家に質問してみよう