Database Reference
In-Depth Information
expiration time, and it is what you need to use to actually drive a car. The
driver's license is a lower value credential; it is relatively easy to replace
if lost, as long as you still have your birth certificate. Likewise the birth
certificate is a higher value credential, even though you cannot use it if you
get pulled over for speeding.
Just as renewing your driver's license can be a pain, renewing your access
token whenever it expires can also be a lot of work. This is another reason
to use a standard OAuth2 library, which takes care of renewing your access
tokens automatically. In Python, you can wrap the httplib2.Http()
object you use to make your HTTP requests with one that does the access
token bookkeeping and adds authorization to all your requests:
>>>import httplib2
>>>http = creds.authorize(httplib2.Http())
The resulting http object can be used to talk to BigQuery or any other
Google API without worrying any further about authentication.
If this protocol sounds complicated, it is even more complicated than it
sounds, since some details are omitted. As mentioned elsewhere, you
probably shouldn't implement this yourself. The Google APIs client libraries
are available for most programming languages and can dramatically
simplify the process of getting a fresh access token. Listing 5.1 shows the full
process of getting OAuth2 credentials in Python.
Listing 5.1 : OAuth2 credential authorization (auth.py)
'''Handles credentials and authorization.
This module is used by the sample scripts to handle
credentials and
generating authorized clients. The module can also be
run directly
to print out the HTTP authorization header for use in
curl commands.
Running:
python auth.py
will print the header to stdout. Note that the first
time this module
is run (either directly or via a sample script) it
will trigger the
 
 
Search WWH ::




Custom Search