Now i manually copy & paste the Authorization key,
code:
<?php
namespace Zero\Storelocator\Block;
class Customerreview extends \Magento\Framework\View\Element\Template
{
public function __construct(
\Amasty\Storelocator\Block\view\Attributes $attributes,
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
array $data = []
) {
$this->_attributes = $attributes;
$this->scopeConfig = $scopeConfig;
parent::__construct($context, $data);
}
protected function _prepareLayout()
{
parent::_prepareLayout();
}
public function getCustomerReview(){
//Here you need to check system.xml file and get section_id/group_id/field_id
$authentication = $this->scopeConfig->getValue('customerreview/general/review_auth', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$accountId = $this->scopeConfig->getValue('customerreview/general/review_account_id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$authorization = "Authorization:".$authentication;
$url = 'https://mybusiness.googleapis.com/v4/accounts/'.$accountId.'/locations/45545454545454545454545/reviews';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
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);
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/output.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info(print_r('line no:42'. $output, true));
$allData = json_decode($output, TRUE); // You will get all the data
return $allData;
}
public function getCustomAttributes()
{
if ($this->_attributes->getLocationAttributes()) {
return '';
}
return $this->_attributes->getLocationAttributes();
}
}
How to do Auto-refresh google business review Authorization key?