google api令牌已过期或被吊销?

2024-09-26 17:51:28 发布

您现在位置:Python中文网/ 问答频道 /正文

一周前,我建立了一个使用谷歌驱动api的discord机器人。这个机器人在一个网络托管服务器上工作了一周,今天我检查了一下,每次我启动这个机器人,它都会给我这个错误

client_secret.json-drive-v3-(['https://www.googleapis.com/auth/drive'],)
['https://www.googleapis.com/auth/drive']
Traceback (most recent call last):
  File "C:\Users\Unknown1\Documents\discordbot\bot.py", line 5, in <module>
    from googledrive import find_recent
  File "C:\Users\Unknown1\Documents\discordbot\googledrive.py", line 10, in <module>
    service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
  File "C:\Users\Unknown1\Documents\discordbot\Google.py", line 28, in Create_Service
    cred.refresh(Request())
  File "C:\Users\Unknown1\AppData\Local\Programs\Python\Python39\lib\site-packages\google\oauth2\credentials.py", line 200, in refresh
    access_token, refresh_token, expiry, grant_response = _client.refresh_grant(
  File "C:\Users\Unknown1\AppData\Local\Programs\Python\Python39\lib\site-packages\google\oauth2\_client.py", line 248, in refresh_grant
    response_data = _token_endpoint_request(request, token_uri, body)
  File "C:\Users\Unknown1\AppData\Local\Programs\Python\Python39\lib\site-packages\google\oauth2\_client.py", line 124, in _token_endpoint_request
    _handle_error_response(response_body)
  File "C:\Users\Unknown1\AppData\Local\Programs\Python\Python39\lib\site-packages\google\oauth2\_client.py", line 60, in _handle_error_response
    raise exceptions.RefreshError(error_details, response_body)
google.auth.exceptions.RefreshError: ('invalid_grant: Token has been expired or revoked.', '{\n  "error": "invalid_grant",\n  "error_description": "Token has been expired or revoked."\n}')
PS C:\Users\Unknown1\Documents\discordbot>

我检查了client_secret_file.json并从google cloud api凭据中重新下载了它,它仍然是一样的。我不知道从这里到哪里去解决这个问题

import pandas as pd
import datetime

CLIENT_SECRET_FILE = 'client_secret.json'
API_NAME = 'drive'
API_VERSION = 'v3'
SCOPES = ['https://www.googleapis.com/auth/drive']

service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)

#in the google drive web link, there will be a folder id.

folder_id = '1ANm4frKaL_JeMEewRMDBLWiiY3Srh-B-'

query = f"parents = '{folder_id}'"

response = service.files().list(q=query).execute()
files = response.get('files')
nextPageToken = response.get('nextPageToken')

while nextPageToken:
    response = service.files().list(q=query,pageToken=nextPageToken).execute()
    files.extend(response.get('files'))
    nextpageToken = response.get('nextPageToken')

df = pd.DataFrame(files)

我已经建立了一个新的项目,OAuth 2.0客户端ID凭据,在这个youtube视频之后:https://www.youtube.com/watch?v=FAM_4J7ywcE&ab_channel=nouthemes

并删除了旧文件,希望用新文件替换客户机密文件。现在我得到一个新的错误:

client_secret.json-drive-v3-(['https://www.googleapis.com/auth/drive'],)
['https://www.googleapis.com/auth/drive']
Traceback (most recent call last):
  File "C:\Users\Unknown1\Documents\discordbot\bot.py", line 5, in <module>
    from googledrive import find_recent
  File "C:\Users\Unknown1\Documents\discordbot\googledrive.py", line 10, in <module>
    service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
  File "C:\Users\Unknown1\Documents\discordbot\Google.py", line 28, in Create_Service
    cred.refresh(Request())
  File "C:\Users\Unknown1\AppData\Local\Programs\Python\Python39\lib\site-packages\google\oauth2\credentials.py", line 200, in refresh
    access_token, refresh_token, expiry, grant_response = _client.refresh_grant(
  File "C:\Users\Unknown1\AppData\Local\Programs\Python\Python39\lib\site-packages\google\oauth2\_client.py", line 248, in refresh_grant
    response_data = _token_endpoint_request(request, token_uri, body)
  File "C:\Users\Unknown1\AppData\Local\Programs\Python\Python39\lib\site-packages\google\oauth2\_client.py", line 124, in _token_endpoint_request
    _handle_error_response(response_body)
  File "C:\Users\Unknown1\AppData\Local\Programs\Python\Python39\lib\site-packages\google\oauth2\_client.py", line 60, in _handle_error_response
    raise exceptions.RefreshError(error_details, response_body)
google.auth.exceptions.RefreshError: ('deleted_client: The OAuth client was deleted.', '{\n  "error": "deleted_client",\n  "error_description": "The OAuth client was deleted."\n}')

我卡住了


Tags: inpyclienttokenapiresponsegoogleline

热门问题