PHP code example of spotonlive / php-google-my-business

1. Go to this page and download the library: Download spotonlive/php-google-my-business library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spotonlive / php-google-my-business example snippets


$accounts = $service->accounts->listAccounts()->getAccounts();
$locations = $service->accounts_locations->listAccountsLocations($accounts[0]['name']); // get locations for the first account
$request = new \Google_Service_MyBusiness_ReportLocationInsightsRequest;
$request->setLocationNames($locations[0]['name']); // set first location to pull data for
$actions = new \Google_Service_MyBusiness_BasicMetricsRequest;
$actions->setMetricRequests(['metric' => 'ALL']);
$time = new \Google_Service_MyBusiness_TimeRange;
$time->setStartTime('2019-10-02T15:01:23.045123456Z');
$time->setEndTime('2020-01-31T15:01:23.045123456Z');
$actions->setTimeRange($time);
$request->setBasicRequest($actions);
$insights = $service->accounts_locations->reportInsights($accounts[0]['name'], $request);
print_r($insights); // see object result structure / insights available