1

I am trying to use the next page token from the first page results that are retrieved by the call to the Google Places, using the following code:

   def pins_in_area
            @client = GooglePlaces::Client.new('api_key_XXXXX')
            @results = @client.spots(params[:lat], params[:long], :radius => params[:radius])
            puts @results
            next_page_token = @results.last.nextpagetoken
            puts next_page_token #spots_by_pagetoken
            next_spots = @client.spots_by_pagetoken(next_page_token)
            puts next_spots

... end

But, I encounter the following error, not sure why:

Completed 500 Internal Server Error in 258ms (ActiveRecord: 0.0ms)

GooglePlaces::InvalidRequestError (GooglePlaces::InvalidRequestError):
  app/controllers/api/v1/pins_controller.rb:89:in `pins_in_area'


  Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_source.erb (13.1ms)
  Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (35.1ms)
  Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.0ms)
  Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (101.1ms)
8
  • You should look at the content of params[:lat], params[:long] and params[:radius]. One or more of them may be wrong type or nil.
    – Joeyjoejoe
    Jun 29, 2016 at 13:26
  • Thank you for your help ! The codes executes okau until the following line: next_spots = @client.spots_by_pagetoken(next_page_token). I can get the results and next_page_token, but somehow spots_by_pagetoken(next_page_token) fails. Jun 29, 2016 at 13:28
  • What s the output of "puts next_page_token"?
    – Joeyjoejoe
    Jun 29, 2016 at 13:37
  • It is something like: CoQC8wAAAMa-UPK2AUTrpuNKpwxHzsbyVBFVHmqlW9T8KRvMrJ020V4Lv_bfXX6k2EzCrviga7lpBZdZxFWivA_ki8GUp9d9DxoGq1dfkiXFRz57Pb0NdumxVQRQ76KZuDPdFmNKAYlKFrc724VlfoSOqCExH4xQQDf4AMaR4KkEDeg-qA0Fg5O3hOTjpKDvJJomunOq_-ZFg_DUxRl_pU-oYEA_JgHLgldhmTWijkEge4G_iPrdn2tm1rYwLb9QTx2jTK-JKkMt1PBAY6BlkSTBJ9RwAzAdHKVU6a69dS_Npw_wCLP793l_KPzV35zZFc7WnKRpszebIpgTUf9p1pTKd7mmvZYSEHxsKfUWDJZWDhnK8FqbQeEaFI6-ju-6FY-V66SihOQbkfHYx8Wd Jun 29, 2016 at 13:40
  • Try to edit your client definition like this: @client = GooglePlaces::Client.new('api_key_XXXXX', {:lat => params[:lat], :lng => params[:long], :radius => params[:radius]})
    – Joeyjoejoe
    Jun 29, 2016 at 13:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.