I have an account id and location id, how to run the following script in Magento 2

$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

I want to share these review details into my custom phtml file, what is the best approach to achieve this?

1 Answer 1


To achive this into your website, you need to do like this one.

  1. Create custom Block for the phtml file.

  2. Do the code into block file by passing the proper parameter required to access the information.

  3. Now call assign that block type of your phtml file and then call block function into your phtml file.

  • Can you pls explain in details, so that i can write the module
    – zus
    Apr 28, 2021 at 12:48
  • I am getting values from google business client api, how to include it into the custom module block, can you pls help me with that.
    – zus
    Apr 29, 2021 at 1:46
  • magento.stackexchange.com/q/336365/57334 can u pls help me, thanks.
    – zus
    Apr 29, 2021 at 2:34
  • I am using Google client api library in in xampp/htdocs/reviewapi/test.php, this is return my reviews. How to convert this thing into my module.
    – zus
    Apr 29, 2021 at 4:01
  • I am new this concept, there is minimum of resources only available, can you pls help me on this, really appreciated.
    – zus
    Apr 29, 2021 at 4:03

Your Answer

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

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