Skip to main content
Skip table of contents

Google Search Console OAuth2 Authentication

Step 1. Creating a New Client ID for a Native Application

1. Log in to the developer console.

2. Create a new project:

3. Go to API Manager:

4. Find and enable the Google Search Console API (it is a new name for Webmaster Tools API):

5. Go to Credentials and create a Client ID with Application type "Other" - this way you will get values for "Client ID" and "Client secret":

Step 2. Getting the Authorization Code

1. Go to https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https://www.googleapis.com/auth/webmasters&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_id=<Client ID from step 1>

2. Log in and get the authorization code:

Step 3. Getting the Refresh Token

Copy codes from Steps 1 and 2 to the script below. It will generate a refresh token which will be used to access the protected resource (Search Console data):

SQL
BEGIN
DECLARE string client_id = '<Client ID>';
DECLARE string code = '<Authorization code>';
DECLARE string client_secret = '<Client secret>';
select "refresh_token" from ( call "google_webmaster_tools_src.invokeHttp"("action" => 'POST', 
                                                                           "request"=> 'code=' || urlencode( code,'UTF-8' ) 
                                                                                               || '&client_id=' || urlencode( client_id, 'UTF-8' ) 
                                                                                               || '&client_secret=' || urlencode( client_secret, 'UTF-8' ) 
                                                                                               || '&redirect_uri=' || urlencode( 'urn:ietf:wg:oauth:2.0:oob', 'UTF-8' ) 
                                                                                               || '&grant_type=authorization_code',
                                                                           "endpoint" => 'https://accounts.google.com/o/oauth2/token',
                                                                           "requestContentType" => 'application/x-www-form-urlencoded'
) ) a, XMLTABLE(XMLNAMESPACES( 'http://www.w3.org/2001/XMLSchema-instance' as "xsi" ),'/root/refresh_token' PASSING JSONTOXML('root',to_chars(a.result,'UTF-8'))
    COLUMNS
    "refresh_token" STRING  PATH '.'
) "xml_table";
END


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.