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

Not Able to genrate refresh token For GMB

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

Hi there,

Iam  Trying to generate the Access token using the id_token received while authenticating. But Getting the result as { "error" : "invalid_grant" }

Below is the Code which is used to get the access token


$client_id = 'XXXXXXXXXXX'; //Google client ID
$client_secret = 'XXXXXX'; //Google client secret

        $oauth2token_url = "";
        //construct POST object required for refresh token fetch
        $postvals = array('grant_type' => 'refresh_token',
            'client_id' => $client_id,
            'client_secret' => $client_secret,
            'refresh_token' => $tok);
        $curl = curl_init($oauth2token_url);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $postvals);
        curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

        $json_response = curl_exec($curl);



Please help to solve this issue

1 Expert replyverified_user

Re: Not Able to genrate refresh token For GMB

Google Employee
# 2
Google Employee

Hi @silvester c,


For generating OAuth 2.0 access tokens for each Google Account, when you use your whitelisted project’s credentials to obtain an OAuth 2.0 access token for authentication via the Google My Business API, you should be logging in with your specific Google Account. When this token is provided and you are making API calls, you will be able to view and manage all the existing locations within that specific account. You should repeat this process with a single set of OAuth 2.0 credentials for your separate Google Accounts to obtain a token for each Google Account.


In addition, when using the OAuth 2.0 client ID for authorization, you should store the refresh token for future use and use the access token to access the API. Once the access token expires, the application should use the refresh token to obtain a new one. 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 only once.


Since the PHP client library doesn’t currently support the display of detailed error messages, we suggest you follow the Make a simple HTTP request step-by-step guide on the Google Developers site to learn how to use the OAuth 2.0 Playground for troubleshooting errors with detailed error messages when sending requests with data via the Google My Business API.