Created
March 3, 2021 13:58
-
-
Save vijayrana99/5c48e12877251975d085f83f64952510 to your computer and use it in GitHub Desktop.
Retrieve google reviews on website using Curl Request in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cid = 1417698146920752799; //CID of a place can be genrated from https://pleper.com/index.php?do=tools&sdo=cid_converter | |
//execute curl | |
$url = 'https://maps.googleapis.com/maps/api/place/details/json?cid='.$cid.'&key=<API-KEY>'; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_HEADER, 1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HEADER, false); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
$arrayData = json_decode($data, true); // json object to array conversion | |
$result = $arrayData['result']; | |
$total_users = $result['user_ratings_total']; // display total number of users who rated | |
$overall_rating = $result['rating']; // display total average rating | |
$reviews = $result['reviews']; //holds information like author_name, author_url, language, profile_photo_url, rating, relative_time_description, text, time | |
//display on view |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment