Last active
August 29, 2015 14:14
-
-
Save cigalecigales/cc0ed71d5968da325aec to your computer and use it in GitHub Desktop.
[*Ruby*] RubyでFlickr APIを使って画像検索 ref: http://qiita.com/cigalecigales/items/013cc2823a94e6a93a3a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gem install flickraw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby flickr-api-search.rb | |
【タイトル】I love the sound of .... | |
【URL】https://farm9.staticflickr.com/1234/56789977989_e607eab551.jpg | |
【投稿者】abcdefg | |
【投稿日】: 2015-02-05 09:13:39 +0900 | |
【出力可能サイズ(横:縦)】(75 : 75), (150 : 150), (100 : 76), (240 : 183), (320 : 244), (500 : 381), (640 : 488), (800 : 609), (1024 : 780), (1600 : 1219), (1710 : 1303) | |
【説明】the cicadas. Their sound, to me, represents lovely hot sunny days in summer. | |
【タグ】challenge, cicada, sound, summer, hot, insect | |
【タイトル】IMG_1311 | |
【URL】https://farm9.staticflickr.com/9012/34562697012_489159cc01.jpg | |
【投稿者】test1 | |
【投稿日】: 2015-02-03 16:39:13 +0900 | |
【出力可能サイズ(横:縦)】(75 : 75), (150 : 150), (100 : 51), (240 : 123), (320 : 163), (500 : 255), (640 : 327), (800 : 409), (1024 : 523), (1600 : 818), (2048 : 1046), (3558 : 1818) | |
【説明】All Rights Reserved MPNavest 2012 Cicada | |
【タグ】cicada | |
【タイトル】Nymph Skin of a Cicada Insect | |
【URL】https://farm9.staticflickr.com/3456/78900897590_7926f7ec2b.jpg | |
【投稿者】Ai ueo | |
【投稿日】: 2015-02-03 01:18:27 +0900 | |
【出力可能サイズ(横:縦)】(75 : 75), (150 : 150), (100 : 67), (240 : 160), (320 : 213), (500 : 334), (640 : 427), (800 : 534), (1000 : 667), (1000 : 667) | |
【説明】غلاف جاف خرجت منه حشرة سيكادا | |
【タグ】cicada, insect, shell, nymph, skin, nature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'flickraw' | |
FlickRaw.api_key = 'API_KEY' | |
FlickRaw.shared_secret = 'API_SECRET' | |
# 検索タグ | |
word = "cicada" | |
# tag: 検索タグ。 | |
# sort: ソート順。デフォルトは「date-posted-desc」。 | |
# 「relevance」は関連度の高さでソート。 | |
# per_page: 検索した時の取得件数。デフォルトは100件。 | |
images = flickr.photos.search(tags: word, sort: "relevance", per_page: 3) | |
images.each do |image| | |
info = flickr.photos.getInfo :photo_id => image.id, :secret => image.secret | |
sizes = flickr.photos.getSizes :photo_id => image.id | |
size_list = sizes.map{ |size| "(#{ size.width } : #{ size.height })"}.join(", ") | |
posted = Time.at(info.dates.posted.to_i).to_s | |
url = FlickRaw.url image | |
tags = info.tags | |
tag_list = tags.map{ |tag| "#{ tag }" }.join(", ") | |
puts "【タイトル】" + image.title | |
puts "【URL】" + url | |
puts "【投稿者】"+ info.owner.username | |
puts "【投稿日】: " + posted | |
puts "【出力可能サイズ(横:縦)】" + size_list | |
puts "【説明】" + info.description | |
puts "【タグ】" + tag_list | |
puts "" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment