manuxi/google-reviews-bundle

Bundle to get Google reviews easily

Installs: 1 409

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 2

Open Issues: 1

Type:symfony-bundle

v1.0.3 2023-10-29 20:33 UTC

This package is auto-updated.

Last update: 2024-03-29 21:30:11 UTC


README

I made this bundle to easily get Google reviews since I haven't found an extension which did this job well. Curl is used to grab data from the Google places api. To avoid excessive api access, the result can be cached (see configuration options). The review data is deserialized to a model for further use.

Install the package with:

composer require manuxi/google-reviews-bundle

If you're not using Symfony Flex, you'll also need to add the bundle in your config/bundles.php file:

Manuxi\GoogleReviewsBundle\ManuxiGoogleReviewsBundle::class => ['all' => true],

Usage

// src/Controller/MyController.php
use Manuxi\GoogleReviewsBundle\ManuxiGoogleReviews;
// ...
class MyController
{
    public function index(ManuxiGoogleReviews $googleReviews)
    {
        $reviews = $googleReviews->getReviews();
        $overallCount = $googleReviews->getReviewsCount();
        // ...
    }
}

You can also access this service directly using the id manuxi_google_reviews.google_reviews.

You can modify the offset and the length of the reviews:

// ...
$reviews = $googleReviews->getReviews(2, 3); //returns 3 elements, starting at offset 2
// ...

Twig usage

The extension comes with two twig functions which will give you the overall count and the reviews themselves.

{% for review in get_google_reviews(1,2) %}
    {{ dump(review) }}
{% endfor %}

Configuration

To use this extension please refer to https://developers.google.com/maps/documentation/embed/get-api-key to get your api key. You also need the CID of the specific business partner. To get it see here: https://www.sterlingsky.ca/how-to-find-the-cid-number-on-google-maps/.

The extension is configured directly by creating a new config/packages/manuxi_google_reviews.yaml file. The mentioned api-key and cid must be placed here just as the default values:

# config/packages/manuxi_google_reviews.yaml
manuxi_google_reviews:
    connector:
        # api-key
        api_key: 
        # CID
        cid: 
        # locale, defaults to en
        locale: en
    cache:
        # I suggest caching!
        enabled: true
        pool: cache.app
        ttl: 86400

Contributing

For the sake of simplicity this extension was kept small. It is tested only with my own tiny Google account (which has only 5 reviews in it). Please feel comfortable submitting issues or pull requests, I'd be glad to get feedback to improve the extension :).