Since this is a command-line app you will want to set the redirect_uri
to: 'urn:ietf:wg:oauth:2.0:oob'. I will file a bug internally to
get the sample in the docs updated.
The handling of OAuth 2.0 in that sample is intentionally kept short
to get the sample on a single page. If
you are building a command-line app for everyday use I'd suggest
looking at some of the samples in the
google-api-python-client library, for example the Google+ sample:
This keeps the client_id and client_secret in a separate file,
client_secrets.json. You can also
look at the keyring sample, which stores the final generated
credentials in your keyring software. Note
that you'll need the python keyring library installed to use it: