Я кодирую приложение в python, которое подключается к API Google Drive через учетную запись службы. Он отлично работает при подключении и создании файла, но когда я пытаюсь загрузить файл, выдает следующее сообщение об ошибке:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
Мой код выглядит так
def credentials_from_file():
from google.oauth2 import service_account
import googleapiclient.discovery
SCOPES = [
'https://www.googleapis.com/auth/drive.file'
]
SERVICE_ACCOUNT_FILE = './client_secrets.json'
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
return credentials
credentials = credentials_from_file()
service = discovery.build('drive', 'v3', credentials=credentials)
# Create a folder
folder_metadata = {
'name': 'My_Files',
'mimeType': 'application/vnd.google-apps.folder'
}
cloudFolder = service.files().create(body=folder_metadata).execute()
print ('creado folder: %s' % cloudFolder.get('name'))
print ('id: %s' % cloudFolder.get('id'))
folder_id = cloudFolder.get('id')
# Upload a file in the folder
file_metadata = {
'name': 'A Test File.txt',
'parents': [cloudFolder['id']]
}
with tempfile.NamedTemporaryFile(mode='w') as tf:
tf.write("This is some test data.")
media = MediaFileUpload(tf.name, mimetype='text/plain')
cloudFile = service.files().create(body=file_metadata).execute()
# List files in our folder
query = "'{}' in parents".format(cloudFolder['id'])
filesInFolder = service.files().list(q=query, orderBy='folder',
pageSize=10).execute()
items = filesInFolder.get('files', [])
# Print the paged results
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
print('{0} ({1})'.format(item['name'], item['id']))
#downloading file ---- here is where my code crashes
request = service.files().get_media(fileId=cloudFile['id'])
print("Request: \n")
print(request)
fh = io.BytesIO()
print ("Download File..."+cloudFile['id'])
downloader = MediaIoBaseDownload(fh, request)
done = Fenter code herealse
while done is False:
status, done = downloader.next_chunk()
print ('Download '+coludFile['name']+' %d%%.' % int(status.progress() * 100))
структура файла учетных данных это так:
{
"type": "service_account",
"project_id": "some-project",
"private_key_id": "abc1234abc",
"private_key": "-----BEGIN PRIVATE KEY-----\BLAH BLAH BLAH\n-----END PRIVATE KEY-----\n",
"client_email": "my_email@my_domain.iam.gserviceaccount.com",
"client_id": "1234567890987654321",
"auth_uri": "auth uri",
"token_uri": "token uri",
"auth_provider_x509_cert_url": "cert url",
"client_x509_cert_url": "client cert url"
}
Не могли бы вы помочь мне понять, что я делаю неправильно?