使用 facebook graph api 检索的图像 url 在一定时间后中断
Image urls retrieved using facebook graph api break after certain amount of time
我有一个 rails(ruby 2.2.1, rails 4.2.0) 应用程序使用 koala gem (2.0.0) 检索所有用户所有相册中的图像。 facebook服务的代码为
class FacebookService
attr_reader :graph
def initialize(token)
@graph = Koala::Facebook::API.new(token)
end
def photos
your_photos, photos_of_you = [], []
albums_ids.map do |album_id|
#this query will combine fetch all the photos in any album + comments + likes associated with that image
your_photos += graph.get_connections(album_id, "photos", {limit: 100, fields: ["id", "source", "images", "height", "width", "created_time", "likes", "comments{id, message, from{name, picture}, created_time}"]})
end
photos_of_you = graph.get_connections("me", "photos", {limit: 100, fields: ["id", "source", "images", "height", "width", "created_time", "likes", "comments{id, message, from{name, picture}, created_time}"]})
(your_photos + photos_of_you).flatten
end
def albums_ids
albums.map { |album| album["id"] }
end
def albums
graph.get_connections("me", "albums")
end
end
并已被用作
fb = FacebookService.new current_user.oauth_token
photos = fb.photos
我正在将那些 url 保存在数据库中以供进一步参考。我尝试保存 source 和 images 数组中的最大图像,但 urls 一直无效。问题是当执行上面的代码时,source 和 images 中的 urls 在一定数量后无效时间(比如 2-3 天)。如何检索以后不会损坏的图像 url?
谢谢。
我不久前就此提交了 a bug - 它似乎是设计使然,并且那些过期的 URL 有一些原因。这里的解决方案是实际缓存图像数据,而不仅仅是 URL.
我有一个 rails(ruby 2.2.1, rails 4.2.0) 应用程序使用 koala gem (2.0.0) 检索所有用户所有相册中的图像。 facebook服务的代码为
class FacebookService
attr_reader :graph
def initialize(token)
@graph = Koala::Facebook::API.new(token)
end
def photos
your_photos, photos_of_you = [], []
albums_ids.map do |album_id|
#this query will combine fetch all the photos in any album + comments + likes associated with that image
your_photos += graph.get_connections(album_id, "photos", {limit: 100, fields: ["id", "source", "images", "height", "width", "created_time", "likes", "comments{id, message, from{name, picture}, created_time}"]})
end
photos_of_you = graph.get_connections("me", "photos", {limit: 100, fields: ["id", "source", "images", "height", "width", "created_time", "likes", "comments{id, message, from{name, picture}, created_time}"]})
(your_photos + photos_of_you).flatten
end
def albums_ids
albums.map { |album| album["id"] }
end
def albums
graph.get_connections("me", "albums")
end
end
并已被用作
fb = FacebookService.new current_user.oauth_token
photos = fb.photos
我正在将那些 url 保存在数据库中以供进一步参考。我尝试保存 source 和 images 数组中的最大图像,但 urls 一直无效。问题是当执行上面的代码时,source 和 images 中的 urls 在一定数量后无效时间(比如 2-3 天)。如何检索以后不会损坏的图像 url?
谢谢。
我不久前就此提交了 a bug - 它似乎是设计使然,并且那些过期的 URL 有一些原因。这里的解决方案是实际缓存图像数据,而不仅仅是 URL.