How to generate access code for Google API

This is the first step you need to do for using any Google API request. Google API requests can be send using an ‘access token’ which can be created from a ‘refresh token’. But in order to create the refresh token, you need to allow the API permissions you want to use for the Google account through a web page. This will give you an access code which is required for creating a refresh token. This permission approval and code generation is required every time you need to create a new refresh token.

Replace the required values in the following URL and open the URL in a browser window where you are Google account is logged in.

https://accounts.google.com/o/oauth2/v2/auth?scope={required scope}&access_type=offline&include_granted_types=true&response_type=code&state=state_parameter_passthrough_value&redirect_uri=http://localhost&client_id={client ID}

e.g.

https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/drive.file&access_type=offline&include_granted_types=true&response_type=code&state=state_parameter_passthrough_value&redirect_uri=http://localhost&client_id=################.apps.googleusercontent.com

Leave a comment

Your email address will not be published. Required fields are marked *