这是代码。谁能找到原因?该程序用于显示朋友相册中的照片。
我认为这个程序使用了 facebook api 3 次,所以可能有重点。但我对事情没有任何想法,而不是这段代码。
graph = Koala::Facebook::API.new(session[:access_token])
freegraph = Koala::Facebook::API.new
friends = graph.get_object("me/friends")
friendsIds = Array.new
friends.each do |f| friendsIds << f["id"] end
fsinfo = freegraph.get_objects(friendsIds)
@realFriends = Array.new
fsinfo.each do |f|
if f[1]["gender"].present? && (f[1]["gender"] != "male")
@realFriends << f[1]
end
end
rFids = @realFriends.map do |rF| rF["id"] end
albums = graph.get_object("albums?ids="+rFids.join(","))
album_ids = Array.new
albums.each do |user|
album_ids += user[1]["data"].map do |a| a["id"] end
end
randAlbumIds = Array.new
20.times do
randAlbumIds << album_ids.at(rand(album_ids.count))
end
imgList = graph.get_object("photos?ids="+randAlbumIds.join(","))
imgObjs = Array.new
imgList.each do |img|
imgObjs += img[1]["data"]
end
if params[:tags].present?
@photos = imgObjs.select do |i| i["tags"].present? end
else
@photos = imgObjs
end