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

Unable to PATCH location with v3

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

{"Google.Apis.Requests.RequestError Requested entity was not found. [404] Errors [Message [Requested entity was not found.] Location[ - ] Reason[notFound] Domain[global]"}

 

I get the this error no matter what I try.

 

I'm using the C# library and have approved access to the API.

 

string MybusinessServiceScope = "https://www.googleapis.com/auth/plus.business.manage";
			String serviceAccountEmail = "< Text has been removed to protect private information >";

			var certificate = new X509Certificate2(_serviceP12File, _key, X509KeyStorageFlags.Exportable);

			ServiceAccountCredential credential = new ServiceAccountCredential(
				   new ServiceAccountCredential.Initializer(serviceAccountEmail)
				   {
					   Scopes = new[] { MybusinessServiceScope },
				   }.FromCertificate(certificate));

			return new MybusinessService(new BaseClientService.Initializer()
			   {
				   HttpClientInitializer = credential,
				   ApplicationName = "< Text has been removed to protect private information >",
			   });

var result = locationsResource.Patch(location, location.Name).Execute();

 

Could someone please tell me how to get past this?

 

Best regards

Dennis

 

 

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Dennis B
July 2016

Re: Unable to PATCH location with v3

Google Employee
# 2
Google Employee

Hi @Dennis B,

 

Due to the complexities involved in using service accounts with the Google My Business API, we strongly recommend using the OAuth 2.0 installed application flow and persisting the refresh token. This way, your application will always be able to request a new access token when necessary. This process requires a user to manually authorize the application during the OAuth 2.0 installed applications flow only once.

 

For a service account, your application uses the client ID and one private key to create a signed token and sends it in a request to the Google OAuth 2.0 Authorization Server for an access token to access a Google API. When the token expires, the application repeats the process. Judging from the source code you provided, the error is caused by you not setting the email address of the user account the application is trying to impersonate to access their Google My Business account and location data. Please note that a one-time user consent is required for a service account to be able to access the Google My Business account and location data on behalf of a particular end user. The end users will have to log in with their Google Accounts to manually authorize the application using OAuth 2.0 Authorization. They can perform this process during the OAuth 2.0 installed applications flow or using OAuth 2.0 Playground. This process needs to be done only once. When you prepare to make authorized API calls using the service account, you specify the user to impersonate by specifying the email address of the user account for access to their Google My Business account and location data. If the end users later want to revoke the application’s access to their Google My Business account and location data, they can remove the authorized app from the Apps connected to your account page of their accounts.

 

The following is a code snippet for using a service account with the API Client Library for .NET:
           // The scope of Google My Business API
           string MybusinessServiceScope = "https://www.googleapis.com/auth/plus.business.manage";
           String serviceAccountEmail = "123456789000-abc123def456@developer.gserviceaccount.com";

           var certificate = new X509Certificate2(@"MyProject.p12", "notasecret", X509KeyStorageFlags.Exportable);

           ServiceAccountCredential credential = new ServiceAccountCredential(
              new ServiceAccountCredential.Initializer(serviceAccountEmail)
              {
                  Scopes = new[] { MybusinessServiceScope },
                  User = "user@example.com"
              }.FromCertificate(certificate));

           // Create the service.
           var service = new MybusinessService(new BaseClientService.Initializer()
           {
               HttpClientInitializer = credential,
               ApplicationName = "Google My Business API Sample",
           });

We hope this helps solve your problem.

Thanks,

The Google My Business API team

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Dennis B
July 2016

Re: Unable to PATCH location with v3

Google Employee
# 2
Google Employee

Hi @Dennis B,

 

Due to the complexities involved in using service accounts with the Google My Business API, we strongly recommend using the OAuth 2.0 installed application flow and persisting the refresh token. This way, your application will always be able to request a new access token when necessary. This process requires a user to manually authorize the application during the OAuth 2.0 installed applications flow only once.

 

For a service account, your application uses the client ID and one private key to create a signed token and sends it in a request to the Google OAuth 2.0 Authorization Server for an access token to access a Google API. When the token expires, the application repeats the process. Judging from the source code you provided, the error is caused by you not setting the email address of the user account the application is trying to impersonate to access their Google My Business account and location data. Please note that a one-time user consent is required for a service account to be able to access the Google My Business account and location data on behalf of a particular end user. The end users will have to log in with their Google Accounts to manually authorize the application using OAuth 2.0 Authorization. They can perform this process during the OAuth 2.0 installed applications flow or using OAuth 2.0 Playground. This process needs to be done only once. When you prepare to make authorized API calls using the service account, you specify the user to impersonate by specifying the email address of the user account for access to their Google My Business account and location data. If the end users later want to revoke the application’s access to their Google My Business account and location data, they can remove the authorized app from the Apps connected to your account page of their accounts.

 

The following is a code snippet for using a service account with the API Client Library for .NET:
           // The scope of Google My Business API
           string MybusinessServiceScope = "https://www.googleapis.com/auth/plus.business.manage";
           String serviceAccountEmail = "123456789000-abc123def456@developer.gserviceaccount.com";

           var certificate = new X509Certificate2(@"MyProject.p12", "notasecret", X509KeyStorageFlags.Exportable);

           ServiceAccountCredential credential = new ServiceAccountCredential(
              new ServiceAccountCredential.Initializer(serviceAccountEmail)
              {
                  Scopes = new[] { MybusinessServiceScope },
                  User = "user@example.com"
              }.FromCertificate(certificate));

           // Create the service.
           var service = new MybusinessService(new BaseClientService.Initializer()
           {
               HttpClientInitializer = credential,
               ApplicationName = "Google My Business API Sample",
           });

We hope this helps solve your problem.

Thanks,

The Google My Business API team

Re: Unable to PATCH location with v3

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
I change to use the OAuth Application flow and got that working.

Maybe you shoud update the documentation to give the correct best practice instead of suggesting the service account way.

Re: Unable to PATCH location with v3

Google Employee
# 4
Google Employee

Hi @Dennis B,

 

We will keep your suggestion in mind for our future documentation releases.

 

Thanks,

The Google My Business API team