Я сделал это по-другому, я создал файл с именем googleData. php, который я буду выполнять два раза в день, используя задание cron, со следующим кодом:
<?php
include 'config.php';
$api_key = $config["apikey"];
$placeId = $config["locationId"];
$response = file_get_contents("https://maps.googleapis.com/maps/api/place/details/json?placeid=$placeId&fields=name,rating,reviews&key=$api_key");
//$json = str_replace(array("\n", "\r"), ' ', $response);
$fp = fopen('googleData.json', 'w');
fwrite($fp, $response);
fclose($fp);
?>
this дал следующий ответ в файле googleData. json:
{
"html_attributions" : [],
"result" : {
"name" : "name",
"rating" : 4.7,
"reviews" : [
{
"author_name" : "NAME",
"author_url" : "URL",
"language" : "en",
"profile_photo_url" : "PHOTO_URL",
"rating" : 5,
"relative_time_description" : "5 months ago",
"text" : "Very helpful.",
"time" : 1570537557
},
{
"author_name" : "NAME",
"author_url" : "URL",
"language" : "en",
"profile_photo_url" : "PHOTO_URL",
"rating" : 5,
"relative_time_description" : "5 months ago",
"text" : "Very helpful.",
"time" : 1570537557
},
{
"author_name" : "NAME",
"author_url" : "URL",
"language" : "en",
"profile_photo_url" : "PHOTO_URL",
"rating" : 5,
"relative_time_description" : "5 months ago",
"text" : "Very helpful.",
"time" : 1570537557
},
{
"author_name" : "NAME",
"author_url" : "URL",
"language" : "en",
"profile_photo_url" : "PHOTO_URL",
"rating" : 5,
"relative_time_description" : "5 months ago",
"text" : "Very helpful.",
"time" : 1570537557
},
{
"author_name" : "NAME",
"author_url" : "URL",
"language" : "en",
"profile_photo_url" : "PHOTO_URL",
"rating" : 5,
"relative_time_description" : "5 months ago",
"text" : "Very helpful.",
"time" : 1570537557
}
]
},
"status" : "OK"
}
, который я мог бы затем использовать в другом файле с именем getreviews. php, который имел следующий код:
var json = $.getJSON("googleData.json", function(response) {
var result = response.result;
})
с помощью которого я смог показать все значения json, которые я получил от Google.
для любопытных, это то, что я имел в конфигурации. php:
<?php
$config["apikey"] = "API_KEY";
$config["locationId"] = "PLACE_ID";
?>