It turns out that there are excellent classes in the Google libraries to make OAuth absolutely trivial, in fact it's really only 3 lines:
- Construct your AuthorizationCodeFlow
- Construct your AuthorizationCodeInstalledApp
- Ask the InstalledApp to authorize the client
Now to make this happen you're going to need to include the relevant Google libs. You can find lots of good info about the libs here google-api-java-client, google-oauth-java-client and google-http-java-client.
The libs necessary for the above are: