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

create a new location google my business app php

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

hi i have try to create a new location using google my business php app  this is my example :



$oLocation = createLocation($locations, $test_acc[0]['name']);

function createLocation($locations, $account)

$location = new Google_Service_Mybusiness_Location();
$address = new Google_Service_Mybusiness_Address();
$address->setAddressLines("Level 5, 48 Pirrama Road");
$businessHours = new Google_Service_Mybusiness_BusinessHours();
$timePeriods = array();
$days = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday");
foreach ($days as $day) {
$timePeriod = new Google_Service_Mybusiness_TimePeriod();
$timePeriods[] = $timePeriod;
$location->setLocationName("Google Sydney");
$location->setPrimaryPhone("02 9374 4000");
$primaryCategory = new Google_Service_Mybusiness_Category();
$primaryCategory->setName("Software Company");
$additionalCategories = array(
"name" => "Computer Service",
"categoryId" => "gcid:computer_service"
"name" => "Corporate Office",
"categoryId" => "gcid:corporate_office"
$labels = array("Recently opened", "High-traffic");

try {
// $createdlocation = $locations->create($account->name, $location, array('languageCode' => 'en-AU', 'validateOnly' => FALSE, 'requestId' => uniqid()));
$createdlocation = $locations->create($account->name, $location, array('languageCode' => 'en-AU', 'validateOnly' => FALSE, 'requestId' => uniqid()));
} catch (Exception $e) {
print "Caught exception: " . $e->getMessage() . "\n";
return null;

return $createdlocation;


i get this response


PHP Fatal error:  Call to a member function create() on null 

1 Expert replyverified_user

Re: create a new location google my business app php

Google Employee
# 2
Google Employee

Hi @Mario R,


The code snippet you provided in your post looks fine to me. If you are using the v3.3 version of PHP client library when creating a new location via the Google My Business API, please make sure you include the correct library file as shown in the following line of code:


include_once "MyBusiness.php";


Please note, since the PHP client library doesn’t currently support the display of detailed error messages, so I suggest you follow the Make a simple HTTP request step-by-step guide on the Google Developers site and try use the OAuth 2.0 Playground to step through the auth flow, and examine the HTTP request/response at each step. This usually helps pinpoint where an application is passing the incorrect info.



The Google My Business API team

create a new location google my business app php

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

hi Shalini S


i have

include_once "MyBusiness.php";

and the result is the same.