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

List Accounts Returns 404 Method not Found with PHP Client Library

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

I am at a loss.  I have enabled the GMB in my developer's console.  I am using the PHP client library, but when I try to list the accounts I get an error "404 Method Not Found".  Any related questions I have seen regarding this error have either been taken to a private thread or are irrelevant to my particular situation.  Any help on this would be greatly appreciated.

 

Here is a question I just thought of.  Does my service account need to be a manager in order to access the information for a business?

2 Expert replyverified_user

Re: List Accounts Returns 404 Method not Found with PHP Client Library

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭
Recommended trouble shooting

Try to get the list using postman
https://mybusiness.googleapis.com/v3/accounts/

This might help with setting up you Oauth

or

Try the Oauth2 play ground

https://developers.google.com/oauthplayground/

Make sure that is working for you

Re: List Accounts Returns 404 Method not Found with PHP Client Library

Google Employee
# 3
Google Employee

Hi @Support O,

 

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. 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.

 

We suggest you use the v1-branch of the repository on GitHub as instructed on the Installation page of the API Client Library for PHP (Beta). Please keep in mind that API Client Library for PHP is separate from our PHP client library.

 

The following is a code snippet for using a service account with v1-branch of the API Client Library for PHP:

 

$service_account_name = '1234567890-a1b2c3d4e5f6g7h8i@developer.gserviceaccount.com'; //Email Address

$key_file_location = 'MyProject.p12'; //key.p12

$key = file_get_contents($key_file_location);

$user_to_impersonate = 'user@example.org';

$cred = new Google_Auth_AssertionCredentials(

  $service_account_name,

  array('https://www.googleapis.com/auth/plus.business.manage'),

  $key,

  'notasecret',                                 // Default P12 password

  'http://oauth.net/grant_type/jwt/1.0/bearer', // Default grant type

  $user_to_impersonate

);

$client->setAssertionCredentials($cred);

if ($client->getAuth()->isAccessTokenExpired()) {

$client->getAuth()->refreshTokenWithAssertion($cred);

}

 

Thanks,

The Google My Business API team

Re: List Accounts Returns 404 Method not Found with PHP Client Library

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭
The Oauth2 play ground is not working for me. I tried using my existing service account following the instructions found at https://developers.google.com/my-business/content/get-started and it gave me a 400 Error: redirect_uti_mismatch saying "The redirect URI in the request, https://developers.google.com/oauthplayground, does not match the ones authorized for the OAuth client.",

I then noticed that there was nowhere in my service client to add a referrer for the oaauth playground like the guide said, so I made a new client ID with web credentials. When I input this information I got to Step 10 where it asks me to send a request, but I got a 404 in return. Also, when I went to the dropdown for available requests, it told me that I had nothing available for that particular ID.

Re: List Accounts Returns 404 Method not Found with PHP Client Library

Google Employee
# 5
Google Employee

Hi @Support O,

 

The 404 Method not found error typically happens when you are using a different Project ID from the one we whitelisted for your company to access the Google My Business API.

 

To avoid redirect URIs, please go to Credentials section in Google Developers Console. Then click on the name of your client ID (Type: Web application) under OAuth 2.0 client IDs section. Then add https://developers.google.com/oauthplayground as a valid redirect URI under Authorized redirect URIs.

 

We’ll reach out to you privately on a separate thread for more details.

Thanks,

The Google My Business API team

Re: List Accounts Returns 404 Method not Found with PHP Client Library

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭
What does it mean that you will reach out to me on a separate thread? Will I get a message from someone?

Re: List Accounts Returns 404 Method not Found with PHP Client Library

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭
Here is my response once I get my token and I get to the 'Configure request to API' portion of the playground

HTTP/1.1 404 Not Found
Alternate-protocol: 443:quic
Content-length: 100
X-xss-protection: 1; mode=block
X-content-type-options: nosniff
Transfer-encoding: chunked
Vary: Origin, X-Origin, Referer
Server: ESF
-content-encoding: gzip
Cache-control: private
Date: Tue, 26 Jul 2016 16:54:33 GMT
X-frame-options: SAMEORIGIN
Alt-svc: quic=":443"; ma=2592000; v="36,35,34,33,32,31,30,29,28,27,26,25"
Content-type: application/json; charset=UTF-8
{
"error": {
"status": "NOT_FOUND",
"message": "Method not found.",
"code": 404
}
}

Re: List Accounts Returns 404 Method not Found with PHP Client Library

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭
I think maybe I cannot get my Web Client ID to work on playground because I signed up with my service account. Why was the method 404 for my service account when attempting to do a php call from my server?

Re: List Accounts Returns 404 Method not Found with PHP Client Library

Google Employee
# 9
Google Employee

Hi @Support O,

 

We have emailed you on 07/25/2016 for more details. Please check your email.

 

Thanks,

The Google My Business API team

Re: List Accounts Returns 404 Method not Found with PHP Client Library

Google Employee
# 10
Google Employee

Hi @Support O,

 

Please use OAuth 2.0 client ID credentials of your whitelisted project and not service account credentials when working with OAuth 2.0 Playground to confirm that you have access to the Google My Business API.

 

Furthermore, please perform all the required steps, especially step 8. Click Authorize APIs., in the Make a simple HTTP request guide on the the Google Developers site to use the OAuth 2.0 Playground for experimenting with the Google My Business API.

Thanks,

The Google My Business API team