2012-04-04 73 views
0

我正在写一个Rails功能(应该)翻阅考拉:: GraphCollection

  1. 导入全部用户的/我/音乐“的
  2. 查找更详细的每个页面中的组50(FB批量API)

导入我工作得很好。批处理与我一起限制循环到前50,但我不知道如何重新运行与偏移量的循环。这是我目前的循环:

Koala::Facebook::BatchOperation.instance_variable_set(:@identifier, 0) 
results = @graph.batch do |batch_api| 
    @music.each do |artist| 
    if(i == 50) 
    break 
    end 
    batch_api.get_object(artist["id"]) 
    i=i+1 
    end 
end 

显然@music[0..50] do |artist|是无效的语法,所以没有运气。

回答

3

,让Google,这是我如何解决我的问题:

artist_ids = music.each do |artist| 
    artist["id"] 
end 
Koala::Facebook::BatchOperation.instance_variable_set(:@identifier, 0) 
artist_ids.in_groups_of(50) do |artists| 
    i=0 
    results = graph.batch do |batch_api| 
    for artist in artists do 
     # ((Your code)) 
     i=i+1 
    end 
    end 
    results.each do |artist| 
     # ((Your code)) 
    end 
end 
+1

虽然更好,但如果你的艺术家/网页/对象的列表是从收集来了,你可以指定你在最初的栏目收集请求,而不是获取ID列表,然后逐一处理。 – RubberDucky 2012-07-05 14:01:23