下一页标记 R Google 地方 API

Next page token R Google Places API

我正在尝试从 R 中的 Google 位置 API 获取餐厅详细信息。我可以成功获得 Google 提供的 20 个结果,但是我意识到它 returns a next_page_token,那么这意味着还有其他结果(这是合乎逻辑的,因为我正在搜索的位置半径 50 公里周围有 20 多家餐馆)。但是,当我使用 next_page_token 时,它 returns NULL。 这是我的代码:

install.packages("googleway")
library(googleway)

key <- 'my key'

df_places <- google_places(search_string = "restaurant", 
                       location = c(-33, 151),
                       page_token = "next_page_token",
                       radius = 50000,
                       key = key)
df_places$results$name
df_places$results$rating
df_places$results$formatted_address
df_places$results$geometry$location

这是 return 没有 next_page_token 的情况:

 [1] "Gennaro's Italian Restaurant"                   
 [2] "Mount Broke Wines & Restaurant"                 
 [3] "Oak Dairy Bar"                                  
 [4] "Bimbadgen"                                      
 [5] "Subway Restaurant"                              
 [6] "Muse Restaurant"                                
 [7] "Ocean Restaurant"                               

等...

这是 return 与 next_page_token 的内容:

> df_places$results$name
NULL

只是想知道我重复做错了什么 return NULL?

首先要检查的是,您使用的是带引号的字符串 "next_page_token",还是从第一个查询 google_places()[=14= 的结果中获得的对象 next_page_token ]

这是您的代码的一个工作示例

library(googleway)

key <- 'api_key'

df_places <- google_places(search_string = "restaurant", 
                           location = c(-33, 151),
                           radius = 50000,
                           key = key)

token <- df_places$next_page_token

df_next_places <- google_places(search_string = "restaurant", 
                           location = c(-33, 151),
                           page_token = token,
                           radius = 50000,
                           key = key)

df_places$results$name[1:5]
# [1] "Gennaro's Italian Restaurant"   "Mount Broke Wines & Restaurant"
# [3] "Oak Dairy Bar"                  "Bimbadgen"                     
# [5] "Subway Restaurant"

df_next_places$results$name[1:5]
# [1] "RidgeView Restaurant"          "Emerson's Cafe and Restaurant"
# [3] "EXP. Restaurant"               "Margan Restaurant & Winery"   
# [5] "AL-Oi Thai Restaurant"