How to handle generate Google Business Reviews Authorization Bearer Token?

I am using Google Business Review API, every time i manually copy and paste the Bearer token, how to handle this?,

My code :

<?php namespace ZeroStorelocatorBlock; class Customerreview extends MagentoFrameworkViewElementTemplate { public function __construct( AmastyStorelocatorBlockviewAttributes $attributes, MagentoFrameworkViewElementTemplateContext $context, MagentoFrameworkAppConfigScopeConfigInterface $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', MagentoStoreModelScopeInterface::SCOPE_STORE); $accountId = $this->scopeConfig->getValue('customerreview/general/review_account_id', MagentoStoreModelScopeInterface::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 ZendLogWriterStream(BP . '/var/log/output.log'); $logger = new ZendLogLogger(); $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(); } } 

submitted by /u/aveeva7
[link] [comments]