Skip to content

Instantly share code, notes, and snippets.

@odil-io
Last active August 2, 2022 07:42
Show Gist options
  • Save odil-io/ae3644b9c2cff447112131c31a0dec0b to your computer and use it in GitHub Desktop.
Save odil-io/ae3644b9c2cff447112131c31a0dec0b to your computer and use it in GitHub Desktop.
PHP: Get Google Company Reviews
<?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