-1

I'm trying to go to the next page but i had the error request denied i managed a code and i got juste 20 records i used also sleep to hold up the request but without any chance can you help me please:

from googleplaces import GooglePlaces, types, lang
from unidecode import unidecode 
import json
import time
import requests

YOUR_API_KEY = 'AIzaSyAZo0lBWrvWa_aOnt1goJl5Z1imYg0tv-k'
google_places = GooglePlaces(YOUR_API_KEY)
query_result = google_places.nearby_search(
        lat_lng={'lat' : 46.1667, 'lng' : -1.15}, 
        radius=5000,
        types=[types.TYPE_RESTAURANT] or [types.TYPE_CAFE] or [type.TYPE_BAR] or [type.TYPE_CASINO])
time.sleep(10)  


for place in query_result.places:
         place.get_details()
         print place.place_id

         print unidecode(place.name)

if query_result.has_next_page_token:
    query_result_next_page = google_places.nearby_search(
                pagetoken=query_result.next_page_token)
    for pl in query_result.places:
        pl.get_details()
        print pl.place_id
             #places.append(place.place_id)
        print unidecode(pl.name)
Mohammed Rasfa
  • 105
  • 1
  • 11

1 Answers1

0

With pagetoken, you need to include other bunch of parameters from the parent page query. Also, to get the next page results, you need to iterate on the new query.

from googleplaces import GooglePlaces, types, lang
from unidecode import unidecode 
import json
import time
import requests

YOUR_API_KEY = 'AIzaSyAZo0lBWrvWa_aOnt1goJl5Z1imYg0tv-k'
google_places = GooglePlaces(YOUR_API_KEY)
query_result = google_places.nearby_search(
        lat_lng={'lat' : 46.1667, 'lng' : -1.15}, 
        radius=5000,
        types=[types.TYPE_RESTAURANT] or [types.TYPE_CAFE] or [type.TYPE_BAR] or 
              [type.TYPE_CASINO])
time.sleep(10)  


for place in query_result.places:
         place.get_details()
         print place.place_id
         print unidecode(place.name)

if query_result.has_next_page_token:
    query_result_next_page = google_places.nearby_search(
        lat_lng={'lat' : 46.1667, 'lng' : -1.15}, 
        radius=5000,
        types=[types.TYPE_RESTAURANT] or [types.TYPE_CAFE] or [type.TYPE_BAR] or 
              [type.TYPE_CASINO], pagetoken=query_result.next_page_token)
    for pl in query_result_next_page.places:
        pl.get_details()
        print pl.place_id
        #places.append(place.place_id)
        print unidecode(pl.name)
  • I get juste the next page but i can't get all the pages – Mohammed Rasfa Jun 14 '18 at 09:26
  • 1
    If you are using standard google place API, at one call you can get maximum 60 places. The above code will give you 40 places. To get another 20 you need to write the similar child code under query_result_next_page block. For more you have to go for premium plan – Rajat Agarwal Jun 20 '18 at 09:10