Skip to content

Commit

Permalink
add requirements and quickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
davidenders11 committed Sep 19, 2023
1 parent 02c570b commit 60b1714
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Virtual Environment
/bin
/lib

# Secrets
credentials.json
token.json
56 changes: 56 additions & 0 deletions quickstart.py
Original file line number Diff line number Diff line change
@@ -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()
30 changes: 30 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 60b1714

Please sign in to comment.