|
| 1 | +# Copyright 2018 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# [START meet_quickstart] |
| 16 | +from __future__ import print_function |
| 17 | + |
| 18 | +import os.path |
| 19 | + |
| 20 | +from google.auth.transport.requests import Request |
| 21 | +from google.oauth2.credentials import Credentials |
| 22 | +from google_auth_oauthlib.flow import InstalledAppFlow |
| 23 | +from google.apps import meet_v2 |
| 24 | + |
| 25 | + |
| 26 | +# If modifying these scopes, delete the file token.json. |
| 27 | +SCOPES = ['https://www.googleapis.com/auth/meetings.space.created'] |
| 28 | + |
| 29 | + |
| 30 | +def main(): |
| 31 | + """Shows basic usage of the Google Meet API. |
| 32 | + """ |
| 33 | + creds = None |
| 34 | + # The file token.json stores the user's access and refresh tokens, and is |
| 35 | + # created automatically when the authorization flow completes for the first |
| 36 | + # time. |
| 37 | + if os.path.exists('token.json'): |
| 38 | + creds = Credentials.from_authorized_user_file('token.json', SCOPES) |
| 39 | + # If there are no (valid) credentials available, let the user log in. |
| 40 | + if not creds or not creds.valid: |
| 41 | + if creds and creds.expired and creds.refresh_token: |
| 42 | + creds.refresh(Request()) |
| 43 | + else: |
| 44 | + flow = InstalledAppFlow.from_client_secrets_file( |
| 45 | + 'credentials.json', SCOPES) |
| 46 | + creds = flow.run_local_server(port=0) |
| 47 | + # Save the credentials for the next run |
| 48 | + with open('token.json', 'w') as token: |
| 49 | + token.write(creds.to_json()) |
| 50 | + |
| 51 | + try: |
| 52 | + client = meet_v2.SpacesServiceClient(credentials=creds) |
| 53 | + request = meet_v2.CreateSpaceRequest() |
| 54 | + response = client.create_space(request=request) |
| 55 | + print(f'Space created: {response.meeting_uri}') |
| 56 | + except Exception as error: |
| 57 | + # TODO(developer) - Handle errors from Meet API. |
| 58 | + print(f'An error occurred: {error}') |
| 59 | + |
| 60 | + |
| 61 | +if __name__ == '__main__': |
| 62 | + main() |
| 63 | +# [END meet_quickstart] |
0 commit comments