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

许可以下: CC-BY-SA归因
scroll top