2017-12-10 20 views
2

R의 Google 장소 API에서 레스토랑 정보를 가져 오려고합니다. Google에서 제공하는 20 개의 결과를 성공적으로 얻을 수는 있지만, next_page_token을 반환하기 때문에 결과가 있음을 알게됩니다. 다른 결과 (논리적 인 것은 내가 찾고있는 위치의 50km 반경 주변에 20 개 이상의 레스토랑이 있음). 그러나 next_page_token을 사용하면 NULL을 반환합니다. 다음은 내 코드입니다 :다음 페이지 토큰 R Google Places API

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없이 반환 것입니다 :

> df_places$results$name 
NULL 
: 등

[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로 반환 것입니다

내가 반복적으로 다시하는 것이 잘못되어 있는지 궁금하다. NULL?

답변

1

확인하기 위해 우선, 당신은 당신의 코드의 작동 예를 들어 당신이 여기 google_places()

에 첫 번째 쿼리에 결과에서 얻을 인용 된 문자열 "next_page_token" 또는 개체 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" 
+0

이것은 완벽하게 작동했습니다! –