ruby – Google AnalyticsAPI – 分页

我正在使用Google Api Client for
Ruby从Google Analytics下载一些数据(我的Gemfile.lock是google-api-client(0.6.4)).我从谷歌获取数据,但它是如此多,以至于它(或至少它应该)在几页(超过1000行).

我试图使用谷歌的例子(我的代码的一部分)

    request = {
      :api_method => analytics.data.ga.get, 
      :parameters => {
        'ids' => "ga:" + ids, 
        'start-date' => start_date, 
        'end-date' => end_date, 
        'dimensions' => dimensions, 
        'metrics' => metrics,
        'max-results' => 10 #only for testing
      }
    }

    loop do
      result = api.execute(request)
      results << result

      break unless result.next_page_token
      request = result.next_page
    end

嗯……它不起作用.

result.next_page_token #returns always nil

我正在使用Analytics API(v3)

最佳答案 我也经历了同样的事情,使它与下面的代码一起工作

     loop do
        result = api.execute(request)
        results << result
        next_page_uri = result.data.next_link
        break unless next_page_uri
        next_page = result.next_page
        next_page.uri = next_page_uri
        request = next_page
      end

希望这对那些面临同样问题的人有所帮助

点赞