简体   繁体   中英

Error 403 using Google Drive API with Python - Daily Limit for Unauthenticated Use Exceeded

I'm getting the error 403 using the Google Drive API with Python. I can see the files on google drive but when I tryed to download it I got the following error:

    "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."

I'm using the code:

try:
    import argparse
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
    flags = None

SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Drive API Quickstart'

def get_credentials():
    home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)
    credential_path = os.path.join(credential_dir,
                                   'drive-python-quickstart.json')

    store = Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
        flow.user_agent = APPLICATION_NAME
        if flags:
            credentials = tools.run_flow(flow, store, flags)
        else: # Needed only for compatibility with Python 2.6
            credentials = tools.run(flow, store)
        print('Storing credentials to ' + credential_path)
    return credentials

def main():
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    service = discovery.build('drive', 'v3', http=http)

    results = service.files().list(
        q="'0BxZjsrGFMvPSNmprUFp0Y25BNFU' in parents", #first execution...
        pageSize=10,
        fields="nextPageToken, files(id, name)").execute()
    items = results.get('files', [])
    if not items:
        print('No files found.')
    else:
        print('Files:')
        for item in items:
            #print('{0} ({1})'.format(item['name'], item['id']))
            #file_id = '0BxZjsrGFMvPSWmtDYXB6RG5VTHM'
            request = service.files().get_media(fileId='0BxZjsrGFMvPSWmtDYXB6RG5VTHM')
            fh = io.BytesIO()
            downloader = MediaIoBaseDownload(fh, request)
            done = False
            while done is False:
                status, done = downloader.next_chunk()
                #print ("Download %d%%." % int(status.progress() * 100))

if __name__ == '__main__':
    main()

I'm also have the OAuth 2.0 client configured: https://prnt.sc/gqasjz I don't know what I'm doing wrong.

   "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."

Means that you are trying to access a Google API without being authenticated first. The credentials are not being properly applied to your service. It should be popping up and asking you permission to access your data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM