|
21 | 21 | from google.oauth2.credentials import Credentials |
22 | 22 | from google_auth_oauthlib.flow import InstalledAppFlow |
23 | 23 | from googleapiclient.discovery import build |
| 24 | +from googleapiclient.errors import HttpError |
24 | 25 |
|
25 | 26 | # If modifying these scopes, delete the file token.json. |
26 | 27 | SCOPES = ['https://www.googleapis.com/auth/contacts.readonly'] |
@@ -48,21 +49,24 @@ def main(): |
48 | 49 | with open('token.json', 'w') as token: |
49 | 50 | token.write(creds.to_json()) |
50 | 51 |
|
51 | | - service = build('people', 'v1', credentials=creds) |
| 52 | + try: |
| 53 | + service = build('people', 'v1', credentials=creds) |
52 | 54 |
|
53 | | - # Call the People API |
54 | | - print('List 10 connection names') |
55 | | - results = service.people().connections().list( |
56 | | - resourceName='people/me', |
57 | | - pageSize=10, |
58 | | - personFields='names,emailAddresses').execute() |
59 | | - connections = results.get('connections', []) |
| 55 | + # Call the People API |
| 56 | + print('List 10 connection names') |
| 57 | + results = service.people().connections().list( |
| 58 | + resourceName='people/me', |
| 59 | + pageSize=10, |
| 60 | + personFields='names,emailAddresses').execute() |
| 61 | + connections = results.get('connections', []) |
60 | 62 |
|
61 | | - for person in connections: |
62 | | - names = person.get('names', []) |
63 | | - if names: |
64 | | - name = names[0].get('displayName') |
65 | | - print(name) |
| 63 | + for person in connections: |
| 64 | + names = person.get('names', []) |
| 65 | + if names: |
| 66 | + name = names[0].get('displayName') |
| 67 | + print(name) |
| 68 | + except HttpError as err: |
| 69 | + print(err) |
66 | 70 |
|
67 | 71 |
|
68 | 72 | if __name__ == '__main__': |
|
0 commit comments