The sample shows how to obtain a valid token for using Google APIs.
Prerequisites.
You will need a valid OAuth 2.0 client registered in Google API console at
https://console.developers.google.com.
More specifically, you will need
'client id', 'client secret', 'redirect uri' exactly as specified in the
console section 'Credentials' (download as json if you are missing the
redirect url).
Additionally, you will need also API scopes for the
APIs enabled in the console that you intend to use with the token you will be
requesting.
Using the sample.
To trigger a token request the sample needs a couple of parameters from your
client and apis that you will use with the token (specified above).
You
can supply them as environment variables and run the java program or you can
supply them interactively in the command line. Mixing the two options is also
possible, i.e. supply part of the parameters as environment variables and
another part interactively.
The names of the environment variables
that you can use to supply the parameters are:
- GOOGLE_API_CLIENT_ID: The client ID obtained from the API Console.
- GOOGLE_API_CLIENT_SECRET: The client Secret obtained from the API Console
- GOOGLE_API_SCOPES: A valid scope for the api that you will call
Note, that if you do not provide authorization code via
environment variable, the sample will prompt you for any missing parameters
required to form a valid request for the code and generate it for you. Use
it to obtain and supply the code.
Reference
https://dev.twitter.com/oauth/application-only