【发布时间】:2015-09-29 19:15:17
【问题描述】:
我已经使用 dashing 和许多(大部分)现有小部件设置了一个仪表板。到目前为止有效 - see production dashboard here (正在进行中)。
现在我想要一个 Instagram 小部件,它显示 username 拍摄的 n 最新图像。
我找到了一个小部件,它可以显示 long 和 lat 的图像,并且能够配置我的令牌,因此我可以与 Instagram API 对话。
这是我当前小部件originally from @mjamieson's gist on github 的代码。
require 'instagram'
require 'rest-client'
require 'json'
# Instagram Client ID from http://instagram.com/developer
Instagram.configure do |config|
config.client_id = ENV['INSTAGRAM_CLIENT_ID']
config.client_secret = ENV['INSTAGRAM_CLIENT_SECRET']
end
# Latitude, Longitude for location
instadash_location_lat = '45.429522'
instadash_location_long = '-75.689613'
SCHEDULER.every '10m', :first_in => 0 do |job|
photos = Instagram.media_search(instadash_location_lat,instadash_location_long)
if photos
photos.map do |photo|
{ photo: "#{photo.images.low_resolution.url}" }
end
end
send_event('instadash', photos: photos)
end
我得到了这个工作,但想修改给定的 API 调用以仅显示我/我选择的用户拍摄的图像。不幸的是,我对 ruby 或 json 的了解不够,无法弄清楚 Instagram API 文档要我做什么。
我找到了以下网址
https://api.instagram.com/v1/users/{user-id}/media/recent/?access_token={acces-token}
并尝试过(填写了我的凭据)。它正确返回了 json 数据,包括我的图像(以及其他数据)。
如何修改给定的代码以按用户名而不是位置显示图像?
非常感谢任何帮助。
【问题讨论】:
标签: ruby json instagram-api dashing