From 60b17146f0e9890a6dd95b480590378e6bf48133 Mon Sep 17 00:00:00 2001 From: davidenders11 Date: Tue, 19 Sep 2023 11:44:53 -0700 Subject: [PATCH] add requirements and quickstart --- .gitignore | 4 ++++ quickstart.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 30 ++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 quickstart.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index d20c338..d3e1669 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ # Virtual Environment /bin /lib + +# Secrets +credentials.json +token.json diff --git a/quickstart.py b/quickstart.py new file mode 100644 index 0000000..e478380 --- /dev/null +++ b/quickstart.py @@ -0,0 +1,56 @@ +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 googleapiclient.discovery import build +from googleapiclient.errors import HttpError + +# If modifying these scopes, delete the file token.json. +SCOPES = ['https://www.googleapis.com/auth/gmail.readonly'] + + +def main(): + """Shows basic usage of the Gmail API. + Lists the user's Gmail labels. + """ + 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: + # Call the Gmail API + service = build('gmail', 'v1', credentials=creds) + results = service.users().labels().list(userId='me').execute() + labels = results.get('labels', []) + + if not labels: + print('No labels found.') + return + print('Labels:') + for label in labels: + print(label['name']) + + except HttpError as error: + # TODO(developer) - Handle errors from gmail API. + print(f'An error occurred: {error}') + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..007760a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,30 @@ +aiohttp==3.8.5 +aiosignal==1.3.1 +async-timeout==4.0.3 +attrs==23.1.0 +cachetools==5.3.1 +certifi==2023.7.22 +charset-normalizer==3.2.0 +frozenlist==1.4.0 +google-api-core==2.11.1 +google-api-python-client==2.100.0 +google-auth==2.23.0 +google-auth-httplib2==0.1.1 +google-auth-oauthlib==1.1.0 +googleapis-common-protos==1.60.0 +httplib2==0.22.0 +idna==3.4 +multidict==6.0.4 +oauthlib==3.2.2 +openai==0.28.0 +protobuf==4.24.3 +pyasn1==0.5.0 +pyasn1-modules==0.3.0 +pyparsing==3.1.1 +requests==2.31.0 +requests-oauthlib==1.3.1 +rsa==4.9 +tqdm==4.66.1 +uritemplate==4.1.1 +urllib3==1.26.16 +yarl==1.9.2