PHP code example of ostapovich / google-reviews

1. Go to this page and download the library: Download ostapovich/google-reviews library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ostapovich / google-reviews example snippets




stapovich\GoogleReview;

// Initialize the GoogleReview class
$googleReview = new GoogleReview();

// URL of the Google reviews page
$firstUrl = 'https://www.google.com/async/reviewDialog?ei=owqIZv3iLveJxc8PoPCzuAI&opi=89978449&yv=3&cs=1&async=feature_id:0x47e66e2964e34e2d%3A0x8ddca9ee380ef7e0,review_source:All%20reviews,sort_by:qualityScore,is_owner:false,filter_text:,associated_topic:,next_page_token:,async_id_prefix:,_pms:s,_fmt:pc'; // Your First URL here, i add paris
$secondUrl = 'https://www.google.com/async/reviewSort?vet=12ahUKEwj9mbuqlZCHAxWlRvEDHTCpD10Qxyx6BAgBEBU..i&ved=2ahUKEwj9mbuqlZCHAxWlRvEDHTCpD10Qjit6BQgBEKsE&bl=UndH&s=web&opi=89978449&yv=3&cs=1&async=feature_id:0x47e66e2964e34e2d%3A0x8ddca9ee380ef7e0,review_source:All%20reviews,sort_by:newestFirst,is_owner:false,filter_text:,associated_topic:,next_page_token:,_pms:s,_fmt:pc'; // Your Second URL here here, i add paris

try {
    // Fetch all reviews
    $reviews = $googleReview->getReviewsAll($secondUrl, 3); // if you need all reviews do not specify the second parameter

    // Output reviews
    foreach ($reviews as $review) {
        echo "Name: " . $review['name'] . "\n";
        echo "Rating: " . $review['rating'] . "\n";
        echo "Review: " . $review['text'] . "\n\n";
    }
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

// Get general location, rating, and count
$this->getRating($this->getCrawlerObj($firstUrl));
$this->getReviewsCount($this->getCrawlerObj($firstUrl));