|
34 | 34 | import sys |
35 | 35 |
|
36 | 36 | from googleapiclient.discovery import build |
37 | | -from oauth2client.client import SignedJwtAssertionCredentials |
| 37 | +from oauth2client.service_account import ServiceAccountCredentials |
38 | 38 |
|
39 | 39 | def main(argv): |
40 | | - # Load the key in PKCS 12 format that you downloaded from the Google API |
41 | | - # Console when you created your Service account. |
42 | | - f = file('key.p12', 'rb') |
43 | | - key = f.read() |
44 | | - f.close() |
45 | | - |
46 | | - # Create an httplib2.Http object to handle our HTTP requests and authorize it |
47 | | - # with the Credentials. Note that the first parameter, service_account_name, |
48 | | - # is the Email address created for the Service account. It must be the email |
49 | | - # address associated with the key that was created. |
50 | | - credentials = SignedJwtAssertionCredentials( |
51 | | - |
52 | | - key, |
53 | | - scope='https://www.googleapis.com/auth/tasks') |
| 40 | + # Load the json format key that you downloaded from the Google API |
| 41 | + # Console when you created your service account. For p12 keys, use the |
| 42 | + # from_p12_keyfile method of ServiceAccountCredentials and specify the |
| 43 | + # service account email address, p12 keyfile, and scopes. |
| 44 | + credentials = ServiceAccountCredentials.from_json_keyfile_name( |
| 45 | + 'service-account-abcdef123456.json', |
| 46 | + scopes='https://www.googleapis.com/auth/tasks') |
| 47 | + |
| 48 | + # Create an httplib2.Http object to handle our HTTP requests and authorize |
| 49 | + # it with the Credentials. |
54 | 50 | http = httplib2.Http() |
55 | 51 | http = credentials.authorize(http) |
56 | 52 |
|
|
0 commit comments