Browse Source

ca marche ?

master
arthur.barraux 2 years ago
parent
commit
38ad3fd9c3
  1. BIN
      __pycache__/app.cpython-36.pyc
  2. 70
      app.py
  3. 1
      credentials.json
  4. 1
      token.json

BIN
__pycache__/app.cpython-36.pyc

Binary file not shown.

70
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']
service = build('drive', 'v3')
# The ID of a sample document.
DOCUMENT_ID = '195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE'
collection = service.stamps()
request = collection.list(cents=5)
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())
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 = build('drive', 'v3', credentials=creds)
# Retrieve the documents contents from the Docs service.
document = service.documents().get(documentId=DOCUMENT_ID).execute()
print('The title of the document is: {}'.format(document.get('title')))
except HttpError as err:
print(err)
service.close()
if __name__ == '__main__':
main()
# [END docs_quickstart]

1
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"]}}

1
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"}
Loading…
Cancel
Save