AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

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

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


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



if (isset($_GET['code'])) {

$code = $_GET['code'];
//Set the Auth URL
$url = '';

//Set the Auth Parameter
$redirectUri='http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
$params = array(
"client_id" => '',
"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);

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

$output = json_decode($output);
$authUrl = "";
//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" => '',
"client_secret" => 'U5mEAuRvI0GotTJxnwUZyDGT',
"scope" => "",

$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_SSL_VERIFYPEER, false);

$http_data = curl_exec($curl);

print '<pre>';

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

} else {

$url = "";

//Set the Auth Parameter
$params = array(
"response_type" => "code",
"client_id" => '',
"redirect_uri" => 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"],
"scope" => "" //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

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.



Shalini, Google My Business API team