gpt4 book ai didi

r - 下一页 token R Google Places API

转载 作者:行者123 更新时间:2023-12-04 11:11:56 25 4
gpt4 key购买 nike

我正在尝试从 R 中的 Google 地点 API 获取餐厅详细信息。我可以成功获得 Google 提供的 20 个结果,但是我意识到它返回了 next_page_token ,那么这意味着还有其他结果(这是合乎逻辑的,在我搜索的位置的 50 公里半径周围有 20 多家餐厅)。但是当我使用 next_page_token它返回 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

这是它在没有 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"

等等...

这是它返回的内容 next_page_token :
> df_places$results$name
NULL

只是想知道我做错了什么反复返回 NULL ?

最佳答案

首先要检查,您是否使用带引号的字符串 "next_page_token" ,或对象 next_page_token你从结果到第一个查询得到的 google_places()
这是您的代码的工作示例

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"

关于r - 下一页 token R Google Places API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47737644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com