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
3K members online now
3K members online now
For developers who are using the Google My Business API to manage locations
Guide Me

PHP Error calling GET (404)

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

Hi There, i'm trying to get up and running with PHP and get the following error, before even 


Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET (404) Not Found' in /Applications/MAMP/htdocs/by/src/Google/Http/REST.php:76 Stack trace: #0 /Applications/MAMP/htdocs/by/src/Google/Http/REST.php(41): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request)) #1 /Applications/MAMP/htdocs/by/src/Google/Client.php(548): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request)) #2 /Applications/MAMP/htdocs/by/src/Google/Service/Resource.php(190): Google_Client->execute(Object(Google_Http_Request)) #3 /Applications/MAMP/htdocs/by/src/Google/Service/Mybusiness.php(602): Google_Service_Resource->call('list', Array, 'Google_Service_...') #4 /Applications/MAMP/htdocs/by/gmb.php(64): Google_Service_MyBusiness_Accounts_Resource->listAccounts() #5 {main} thrown in /Applications/MAMP/htdocs/by/src/Google/Http/REST.php on line 76


I've checked i've the correct project id (my-business-reviews-manager)

, client_secrets.json and have no problems using the oauth2 playground. Am using the 1.1.1 client library.


Here is the code i'm using adapted from examples from Terry W. 



require 'autoload.php';
include_once "/src/Google/Service/Mybusiness.php";

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

define('APPLICATION_NAME', 'BY Reviews Manager');
define('CREDENTIALS_PATH', 'credentials.json');
define('CLIENT_SECRET_PATH', 'client_secret.json');
$redirect_uri = 'http://localhost:8888/by/oauth2callback.php';
$client = new Google_Client();
// For retrieving the refresh token
We are going to create the Google My Business API
service, and query it.
$mybusinessService = new Google_Service_Mybusiness($client);

$credentialsPath = CREDENTIALS_PATH;
if (isset($_GET['code'])) {
  // Exchange authorization code for an access token.
  $accessToken = $client->authenticate($_GET['code']);
  // Store the credentials to disk.
  if (!file_exists(dirname($credentialsPath))) {
     mkdir(dirname($credentialsPath), 0700, true);
  file_put_contents($credentialsPath, $accessToken);
  $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
  header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
// 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();
// For testing purposes, selects the very first account in the accounts array
$accounts = $mybusinessService->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();
$account = $accountsList[0];
print $account;



Any help much appreciated!





1 Expert replyverified_user

Re: PHP Error calling GET (404)

Google Employee
# 2
Google Employee

Hi @iodigital,


I checked that the Project ID you mentioned in your post is whitelisted for your company to access Google My Business API. Please make sure that you installed the v1 of the Google API Client Library for PHP using Composer as instructed on the Installation page and provide redirect_uri as per your current script in your code.




Please note that you should write your code to anticipate the possibility that a granted token might no longer work for various reasons, and obtain a new token when the existing token is deemed invalid.



The Google My Business API team