Giter Site home page Giter Site logo

Comments (7)

mallardduck avatar mallardduck commented on May 28, 2024 12

@jrean & @SachinAgarwal1337: Good News!

The issue is related to how the pagination works. Google's API documents state:

There is a short delay between when a next_page_token is issued, and when it will become valid. Requesting the next page before it is available will return an INVALID_REQUEST response. Retrying the request with the same next_page_token will return the next page of results.

As such, adding a 2 second delay to the subsequent page requests fixes this issue. From my testing a 1 second delay was not enough to get around this, so 2 seconds is what I landed on. Because this is a timing related concern dictated by: a) google and b) how your code works - I don't think this should be 'fixed'. As not all projects will use the library in the same way, adding the delay in the library wouldn't always be necessary - therefor would slow down usage that doesn't need the delay.

For instance, with my project I've structured it so that I would collect all the results and then process and save them. However I am confident that if I changed my strategy to process the first page results, save them and THEN get the second page then the sleep wouldn't be necessary.

from google-places-api.

mallardduck avatar mallardduck commented on May 28, 2024

Dealing with the same issue here - seems that this feature isn't implemented by the library. The reason it's failing is that pagination requests only require the pagetoken set based on the next_page_token and the key for authentication.

Edit: Details on this feature of the place API found here: https://developers.google.com/places/web-service/search#PlaceSearchPaging

EDIT 2: After further testing this what I shared here is not correct. The issue is not related to extra query parameters - Google's API actually just ignores the extras like you may expect. Leaving this intact but striking out the parts that are not accurate.

from google-places-api.

mallardduck avatar mallardduck commented on May 28, 2024

@SachinAgarwal1337 So it's pretty weird - I thought I could whip up a PR to add this feature, but something is going on. Basically I've been able to make the library support the feature however I'm still getting the "INVALID_REQUEST" status back.

Interestingly though when I enable debug mode for Guzzle the raw curl request looks valid. Not just that, but I can even take the text string from the debug output and it will work correctly in browser. If it weren't for using debug mode I'd be sure that I was still doing something super wrong. However, because the request URL works outside of the PHP script I know the URL being generated isn't the issue.

from google-places-api.

SachinAgarwal1337 avatar SachinAgarwal1337 commented on May 28, 2024

@mallardduck Thank you so much for figuring it out.
And as you mentioned, this doesn't look it needs fixing. I will be closing the issue the.

from google-places-api.

jrean avatar jrean commented on May 28, 2024

I confirm @mallardduck is the right patch to go. I ended up using a sleep() of 2 seconds. 1 second not being enough.

@SachinAgarwal1337 maybe you could update the documentation to mention about this.

from google-places-api.

greg0x46 avatar greg0x46 commented on May 28, 2024

@mallardduck thanks, you saved my brain.

from google-places-api.

zxu10 avatar zxu10 commented on May 28, 2024

Very helpful!!

from google-places-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.