My Business
5.1K members online now
5.1K members online now
For developers who are using the Google My Business API to manage locations
Guide Me

reportInsights php api

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭



im trying to get data from my  gmb accounts but i get this error:


 fatal error:  Argument 2 passed to Google_Service_MyBusiness_AccountsLocations_Resource::reportInsights() must be an instance of Google_Service_MyBusiness_ReportLocationInsightsRequest, none given


this is the script that im using:


require_once 'src/Google/autoload.php'; // or wherever autoload.php is located
require_once 'Mybusiness.php';

define('APPLICATION_NAME', 'google_api');
define('CREDENTIALS_PATH', 'credentials.json');
define('CLIENT_SECRET_PATH', 'client_secret2.json');

$redirect_uri = 'urn:ietf:wg:oauth:2.0:oob';

$client = new Google_Client();
$mybusinessService = new Google_Service_Mybusiness($client);
$credentialsPath = CREDENTIALS_PATH;
$reportInsightsArr= array('locationNames' => 'accounts/xxxxxxxxxxxxxxxxxxxxxxxx/locations/xxxxxxxxxxxxxxxxxxxxxxxx', 'drivingDirectionsRequest' => array('numDays' => 'NINETY'));

// Load previously authorized credentials from a file.
if (file_exists($credentialsPath)) {
$accessToken = file_get_contents($credentialsPath);
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
file_put_contents($credentialsPath, $client->getAccessToken());
} else {
// Request authorization from the user.
$authUrl = $client->createAuthUrl();





1 Expert replyverified_user

Re: reportInsights php api

Google Employee
# 2
Google Employee

Hi @Mario R,


After looking at the code you provided, it seems like you are using the previous version of PHP client library to retrieve location insights and driving metrics through the API. Since we recently introduced location insights in v3.2 versions of client libraries in the Google My Business API, so we suggest you please use the v3.2 version of PHP client library to retrieve location insights in the Google My Business API.


Please let us know if you have any other questions about Google My Business API.



The Google My Business API team

reportInsights php api

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭


in the version i saw this method:

'reportInsights' => array(
'path' => 'v3/{+name}/locations:reportInsights',
'httpMethod' => 'POST',
'parameters' => array(
'name' => array(
'location' => 'path',
'type' => 'string',
'required' => true,


so i tried to use it. can u make a clear example of the method.



Re: reportInsights php api

[ Edited ]
Google Employee
# 4
Google Employee

Hi @Mario R,


I posted an example code for retrieving Location Insights with the PHP client library in another thread. Please check out this answer.