2

I want to show the summary rating and customer review in my phtml file, how to get google business review by using API in a custom module or any best practice pls suggest.

Google Business Review API : https://developers.google.com/my-business/content/review-data#list_all_reviews

Any reference welcome.

2 Answers 2

1
+50
<?php 
$accountId = 'your_account_id';
$locationId = 'your_location_id';

$url = 'https://mybusiness.googleapis.com/v4/accounts/'.$accountId.'/locations/'.$locationId.'/reviews';    
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
/*If data is in xml format
$output = simplexml_load_string($output); */
$allData = json_decode(json_encode($output), TRUE); // You will get all the data
?>
20
  • What is the best approach to use the above script in a custom module? Is it helper beat option?
    – zus
    Apr 13, 2021 at 14:31
  • You have to use cron for getting data repeatedly and run this script in cron then you can store data in DB and get in phtml through block file.
    – Mital Shah
    Apr 14, 2021 at 4:37
  • Do you have any module for this, its very useful for me to understand.
    – zus
    Apr 14, 2021 at 9:37
  • You can refer this module. It's getting data from third party url and stored in DB. github.com/mitaldeveloper/magento2-kiyoh
    – Mital Shah
    Apr 15, 2021 at 5:56
  • Is there any ready made module available?
    – zus
    Apr 21, 2021 at 5:35
1

You should auto-run the PHP scrip every 5 minutes containing API curl code using the cron job.
Learn Cron Job handling here -
https://www.mageplaza.com/devdocs/magento-2-create-cron-job/
Edit
This custom module may be helpful
https://github.com/aitoc/magento-2-google-customer-reviews

12
  • May I know how to get Google reviews, is any custom module should I create?
    – zus
    Apr 23, 2021 at 6:48
  • This may be helpful - github.com/aitoc/magento-2-google-customer-reviews Apr 23, 2021 at 7:46
  • I need to show google business revies on my custom page.
    – zus
    Apr 23, 2021 at 12:27
  • Hi i want to display google customer reviews on my custom phtml page.
    – zus
    Apr 26, 2021 at 4:34
  • Please share some code of your custom phtml page, what you already tried. Apr 26, 2021 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.