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
star_border
Reply

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 :

 

$test_acc=$mybusinessService->accounts->listAccounts();

$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");
$address->setLocality("Pyrmont");
$address->setAdministrativeArea("NSW");
$address->setCountry("AU");
$address->setPostalCode("2009");
$location->setAddress($address);
$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();
$timePeriod->setOpenDay($day);
$timePeriod->setOpenTime("9:00");
$timePeriod->setCloseTime("17:00");
$timePeriod->setCloseDay($day);
$timePeriods[] = $timePeriod;
}
$businessHours->setPeriods($timePeriods);
$location->setRegularHours($businessHours);
$location->setLocationName("Google Sydney");
$location->setStoreCode("GOOG-SYD");
$location->setPrimaryPhone("02 9374 4000");
$primaryCategory = new Google_Service_Mybusiness_Category();
$primaryCategory->setName("Software Company");
$primaryCategory->setCategoryId("gcid:software_company");
$location->setPrimaryCategory($primaryCategory);
$additionalCategories = array(
array(
"name" => "Computer Service",
"categoryId" => "gcid:computer_service"
),
array(
"name" => "Corporate Office",
"categoryId" => "gcid:corporate_office"
)
);
$location->setAdditionalCategories($additionalCategories);
$location->setWebsiteUrl("https://www.google.com.au/");
$labels = array("Recently opened", "High-traffic");
$location->setLabels($labels);

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.

 

Thanks,

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.