How to get google business reviews and display in my custom phtml file
-
06-05-2021 - |
Вопрос
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.
Решение
<?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
?>
Другие советы
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
Не связан с magento.stackexchange