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

reportInsights php api

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

hi,

 

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();
$client->setApplicationName(APPLICATION_NAME);
$client->setAuthConfigFile(CLIENT_SECRET_PATH);
$client->addScope("https://www.googleapis.com/auth/plus.business.manage");
$client->setRedirectUri($redirect_uri);
$client->setAccessType("offline");
$client->setApprovalPrompt("force");
$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);
$client->setAccessToken($accessToken);
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
$client->refreshToken($client->getRefreshToken());
file_put_contents($credentialsPath, $client->getAccessToken());
}
} else {
// Request authorization from the user.
$authUrl = $client->createAuthUrl();
}
$test=$mybusinessService->accounts_locations->reportInsights($reportInsightsArr);
print_r($test);

 

 

 

 

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.

 

Thanks,

The Google My Business API team

reportInsights php api

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

hi 

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.

 

thx

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.

 

Thanks,

Shalini