Skip to content

next_page_token not working #120

@francesco1119

Description

@francesco1119

Hello,

I'm using your useful script in order to retrieve places but the next_page_token seems not working:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from googleplaces import GooglePlaces, types, lang
import time

YOUR_API_KEY = 'PasteHereYourAPIKey'

google_places = GooglePlaces(YOUR_API_KEY)

lat_lng = {'lat': -36.8485, 'lng': 174.763336}

query_result_next = None
# You may prefer to use the text_search API, instead.
query_result = google_places.nearby_search(#location='London,England',
                                            lat_lng=lat_lng, 
                                            radius=10000, 
                                            rankby='distance', 
                                            pagetoken=query_result_next,
                                            types=[types.TYPE_MOVIE_THEATER])

def Find_Places(query_result):
    for place in query_result.places:
        # Returned places from a query are place summaries.
        print (place.name,place.place_id,place.geo_location)

    # If there are additional result pages, lets get it on the next while step
    if query_result.has_next_page_token:
        pagetoken=query_result.next_page_token
        query_result_next = google_places.nearby_search(pagetoken)
        Find_Places(query_result_next)

    time.sleep(3)

Find_Places(query_result)

It returns the error:

Traceback (most recent call last):
  File "Light_Fantail.py", line 35, in <module>
    Find_Places(query_result)
  File "Light_Fantail.py", line 30, in Find_Places
    query_result_next = google_places.nearby_search(pagetoken)
  File "C:\Program Files\Python36\lib\site-packages\googleplaces\__init__.py", line 270, in nearby_search
    raise ValueError('One of location, lat_lng or pagetoken must be passed in.')
ValueError: One of location, lat_lng or pagetoken must be passed in.

Which is strange because I'm passing pagetoken

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions