Last active
August 2, 2022 07:42
-
-
Save odil-io/ae3644b9c2cff447112131c31a0dec0b to your computer and use it in GitHub Desktop.
PHP: Get Google Company Reviews
This file contains 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 | |
$api_key = 'YOUR_PLACES_API_KEY'; | |
$place_id = 'PLACE_ID'; | |
$file = file_get_contents( 'https://maps.googleapis.com/maps/api/place/details/json?placeid=' . $place_id . '&key=' . $api_key ); | |
$json = json_decode( $file ); | |
if ( is_object( $json ) ) : | |
foreach ( $json->result->reviews as $review ) : | |
?> | |
<a href="<?= $review->author_url; ?>"> | |
<img class="img-fluid img-circle" src="<?= $review->profile_photo_url; ?>" alt="<?= $review->author_name; ?>"> | |
</a> | |
<?php | |
echo $review->author_name . ', ' . $review->relative_time_description; | |
for ( $i = 0; $i < $review->rating; $i++ ) : | |
?> | |
<i class="fa fa-star"></i> | |
<?php | |
endfor; | |
echo $review->text; | |
endforeach; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment