diff --git a/__pycache__/app.cpython-36.pyc b/__pycache__/app.cpython-36.pyc new file mode 100644 index 0000000..f56592c Binary files /dev/null and b/__pycache__/app.cpython-36.pyc differ diff --git a/app.py b/app.py index beff6dd..1fb7040 100644 --- a/app.py +++ b/app.py @@ -1,16 +1,68 @@ +# 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 docs_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 googleapiclient.discovery import build -import json +from googleapiclient.errors import HttpError + +# If modifying these scopes, delete the file token.json. +SCOPES = ['https://www.googleapis.com/auth/documents.readonly'] + +# The ID of a sample document. +DOCUMENT_ID = '195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE' + + +def main(): + """Shows basic usage of the Docs API. + Prints the title of a sample document. + """ + 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()) -service = build('drive', 'v3') + try: + service = build('drive', 'v3', credentials=creds) -collection = service.stamps() + # Retrieve the documents contents from the Docs service. + document = service.documents().get(documentId=DOCUMENT_ID).execute() -request = collection.list(cents=5) + print('The title of the document is: {}'.format(document.get('title'))) + except HttpError as err: + print(err) -try: - response = request.execute() - print(json.dumps(response, sort_keys=True, indent=4)) -except HttpError as e: - print('Error response status code : {0}, reason : {1}'.format(e.status_code, e.error_details)) -service.close() \ No newline at end of file +if __name__ == '__main__': + main() +# [END docs_quickstart] \ No newline at end of file diff --git a/credentials.json b/credentials.json new file mode 100644 index 0000000..5847d8b --- /dev/null +++ b/credentials.json @@ -0,0 +1 @@ +{"installed":{"client_id":"114734902818-12qkdhcljn2cjtlffmmag6ahq85ig6bb.apps.googleusercontent.com","project_id":"drive-sync-1673116306810","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"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","redirect_uris":["http://localhost"]}} \ No newline at end of file diff --git a/token.json b/token.json new file mode 100644 index 0000000..b55a5b3 --- /dev/null +++ b/token.json @@ -0,0 +1 @@ +{"token": "ya29.a0AX9GBdULPvaziEUVBLWIIOsklGJfK5NQMK-i4_w75KcevtfVJAPi3VE_Lmal8Dd2A0by2uSlGfeE1GTuCzN573KJWwUtN_B8pwNMms7ICX7DORRWomCH01shCsN7UoC1PZJGtVuTDSsZRLeMboAfZIsjlGNEaCgYKAXUSARMSFQHUCsbCf0kSDh1XJROzQs-xbgNqdA0163", "refresh_token": "1//03yth_jXiKf1MCgYIARAAGAMSNwF-L9IraU74M3oUMX3z-m4tc7HjPWfPCcjfrTzIwocPp0a18ru_PQQ-JdSN9_5upP0eYGkElyk", "token_uri": "https://oauth2.googleapis.com/token", "client_id": "114734902818-12qkdhcljn2cjtlffmmag6ahq85ig6bb.apps.googleusercontent.com", "client_secret": "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", "scopes": ["https://www.googleapis.com/auth/documents.readonly"], "expiry": "2023-01-09T17:16:14.720449Z"} \ No newline at end of file