From bc9577f713dd221bee3d61de65e4d553810d62a9 Mon Sep 17 00:00:00 2001 From: Steve Bazyl Date: Tue, 5 Mar 2024 16:16:20 -0700 Subject: [PATCH] feat: Add Meet API quickstart --- meet/README.md | 1 + meet/quickstart/quickstart.py | 63 ++++++++++++++++++++++++++++++++ meet/quickstart/requirements.txt | 3 ++ 3 files changed, 67 insertions(+) create mode 100644 meet/README.md create mode 100644 meet/quickstart/quickstart.py create mode 100644 meet/quickstart/requirements.txt diff --git a/meet/README.md b/meet/README.md new file mode 100644 index 00000000..588c40a2 --- /dev/null +++ b/meet/README.md @@ -0,0 +1 @@ +Additional samples can be found at https://github.com/googleapis/google-cloud-python/tree/main/packages/google-apps-meet \ No newline at end of file diff --git a/meet/quickstart/quickstart.py b/meet/quickstart/quickstart.py new file mode 100644 index 00000000..077f91d4 --- /dev/null +++ b/meet/quickstart/quickstart.py @@ -0,0 +1,63 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START meet_quickstart] +from __future__ import print_function + +import os.path + +from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials +from google_auth_oauthlib.flow import InstalledAppFlow +from google.apps import meet_v2 + + +# If modifying these scopes, delete the file token.json. +SCOPES = ['https://www.googleapis.com/auth/meetings.space.created'] + + +def main(): + """Shows basic usage of the Google Meet API. + """ + creds = None + # The file token.json stores the user's access and refresh tokens, and is + # created automatically when the authorization flow completes for the first + # time. + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) + # If there are no (valid) credentials available, let the user log in. + if not creds or not creds.valid: + if creds and creds.expired and creds.refresh_token: + creds.refresh(Request()) + else: + flow = InstalledAppFlow.from_client_secrets_file( + 'credentials.json', SCOPES) + creds = flow.run_local_server(port=0) + # Save the credentials for the next run + with open('token.json', 'w') as token: + token.write(creds.to_json()) + + try: + client = meet_v2.SpacesServiceClient(credentials=creds) + request = meet_v2.CreateSpaceRequest() + response = client.create_space(request=request) + print(f'Space created: {response.meeting_uri}') + except Exception as error: + # TODO(developer) - Handle errors from Meet API. + print(f'An error occurred: {error}') + + +if __name__ == '__main__': + main() +# [END meet_quickstart] diff --git a/meet/quickstart/requirements.txt b/meet/quickstart/requirements.txt new file mode 100644 index 00000000..7eee1e6d --- /dev/null +++ b/meet/quickstart/requirements.txt @@ -0,0 +1,3 @@ +google-apps-meet==0.1.6 +google-auth-httplib2==0.1.0 +google-auth-oauthlib==0.4.0 \ No newline at end of file