2017-12-10 9 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

これは完全に機能しました! –