Unable to Patch PhotoURL in Location Google My Business API[ Edited ]
December 2016 - last edited December 2016 by Terry W
We are trying to delete Cover Photo URL or Any Photo URL from Photo OR delete a Additional Category in location to my business account even location is published using c# but get the following error
Re: Unable to Patch PhotoURL in Location Google My Business API
Hi @Scout50 D,
I think you should clean up your code and use better mnemonic variable names because you are using createLocationRequest for a PATCH request, Responselist for a Location object, etc. Your item variable from a foreach loop will always be the last element in the list.
To remove a certain field from a Location object, you can simply assign the null value to that particular field. Note that you should remove the read-only name field from a Location object retrieved from a GET request when using it in a PATCH request, or else you will get a ValidationError. It's best practice to always use a fieldMask for updating specific fields so that your other location data are preserved.
// Gets all accounts for the authenticated user.
var accountsListRequest = service.Accounts.List();
ListAccountsResponse accountsResult = accountsListRequest.Execute();
// For testing purposes, selects the very first account in the accounts array.
Account account = accountsResult.Accounts;
// Lists all locations for the specified account.
var locationsListRequest = service.Accounts.Locations.List(account.Name);
ListLocationsResponse locationsResult = locationsListRequest.Execute();
// For testing purposes, selects the very first location in the locations array.
Location location = locationsResult.Locations;
// Updates one or more fields for the specified location.
string name = location.Name;
location.Name = null;
location.Photos.CoverPhotoUrl = null;
location.AdditionalCategories = null;
var locationUpdateRequest = service.Accounts.Locations.Patch(location, name);
locationUpdateRequest.LanguageCode = "en";
locationUpdateRequest.FieldMask = "photos.coverPhotoUrl,additionalCategories";
locationUpdateRequest.ValidateOnly = false;
location = locationUpdateRequest.Execute();
In addition, you should learn to Make a simple HTTP request via OAuth 2.0 Playground for verifying your results since the C# client library doesn’t currently support the display of detailed error messages.