您可以使用下面的ruby腳本檢索圖像並將其保存到文件。然後,您可以在數據庫中引用該文件,或將最後一個塊替換爲特定數據庫實現的代碼。在不知道數據庫類型和模式的情況下,沒有人能告訴你如何添加一些內容。
require "instagram"
require "restclient"
Instagram.configure do |config|
config.client_id = INSTAGRAM_CLIENT_ID
config.client_secret = INSTAGRAM_CLIENT_SECRET
end
instagram_client = Instagram.client(:access_token => INSTAGRAM_ACCESS_TOKEN)
tags = instagram_client.tag_search('cat')
urls = Array.new
for media_item in instagram_client.tag_recent_media(tags[0].name)
urls << media_item.images.standard_resolution.url
end
urls.each_with_index do |url, idx|
image = RestClient.get(url)
path = Dir.pwd + "/#{idx}.jpg"
File.open(path, 'w') {|f| f.write(image) }
end
來源
2014-04-17 17:56:57
Dan
但是,如何創建應用程序來執行該操作,而不是輸入網址。 –
@BryanChew:你可以使用jQuery.ajax來讀取由該URL生成的json文件。只要確保你使用'dataType:'jsonp'' – JFK