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

Website (if applicable)

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

Hi this is Akhil, I am integrating Google My Business API for my client using PHP. I am facing a problem for which I research a lot but could not find any solution. I am going to explain my problem along with the code I have did so far.

I want to fetch all the reviews for the Business using the API.  As given by google I am using the url  https://mybusiness.googleapis.com/v3/accounts/account_name/locations/location_name/reviews

 

To find the account name and location name using API I am using the code given below

 

//code 

<?php
if (isset($_GET['code'])) {

$code = $_GET['code'];
//Set the Auth URL
$url = 'https://accounts.google.com/o/oauth2/token';

//Set the Auth Parameter
$redirectUri='http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
$params = array(
"client_id" => '769532304982-tvo2u7e8d3kbb836v2ehhrq2v1335mhr.apps.googleusercontent.com',
"client_secret" => 'U5mEAuRvI0GotTJxnwUZyDGT',
"redirect_uri" => $redirectUri,
"grant_type" => "authorization_code",
"code" => $code,
);

/** Init the curl */
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

if ($info['http_code'] === 200) {

$output = json_decode($output);
$authUrl = "https://mybusiness.googleapis.com/v3/accounts";
//after getting the access token going to use it to get list of all accounts
$authorization = array(
"Authorization" => "".$output->token_type." ".$output->access_token."",
"client_id" => '769532304982-tvo2u7e8d3kbb836v2ehhrq2v1335mhr.apps.googleusercontent.com',
"client_secret" => 'U5mEAuRvI0GotTJxnwUZyDGT',
"scope" => "https://www.googleapis.com/auth/plus.business.manage",

);
$curl = curl_init();

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , json_encode($authorization) ));
curl_setopt($curl, CURLOPT_URL, $authUrl);
curl_setopt($curl, CURLOPT_POST, FAlSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);


$http_data = curl_exec($curl);
curl_close($curl);

print '<pre>';

print_r($http_data);
exit;
//$decoded= json_decode(json_encode($output));
//echo $decoded;
} else {
die('An error occured');
}
/** Init the curl */

} else {

$url = "https://accounts.google.com/o/oauth2/auth";

//Set the Auth Parameter
$params = array(
"response_type" => "code",
"client_id" => '769532304982-tvo2u7e8d3kbb836v2ehhrq2v1335mhr.apps.googleusercontent.com',
"redirect_uri" => 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"],
"scope" => "https://www.googleapis.com/auth/plus.business.manage" //I have added scope for webmaster tool

);

$requestTo = $url . '?' . http_build_query($params);

//Redirect the page
header("Location: " . $requestTo);


}

 

//code end

 

But executing this one, getting the error of UNAUTHENTICATED.

 

Please explain me what is the problem in it. I am getting the access token, token type and expiry time, and use that token to fetch all the account name but could not. My email address is akhil.singh@appideasinc.com

Waiting for your positive reply. 

1 Expert replyverified_user

Re: Website (if applicable)

Google Employee
# 2
Google Employee

Hi @Akhil S,

 

Judging from your email address on this board, your company may not have a whitelisted project to access the Google My Business API. So before you use any Google My Business API, you need to have a whitelisted project to access them. You can check out the Prerequisites page of our documentation website to learn more about requesting access to the API.

 

Please note, we are currently only targeting tech-savvy chains and third parties which manage Google My Business data for access to the API. Applicants must also meet minimum feature requirements and product guidelines.

 

Thanks,

Shalini, Google My Business API team