Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
466 views
in Technique[技术] by (71.8m points)

python - google api token expired or revoked?

I have set up a discord bot a week ago that uses google drive api. The bot worked for a week in a web hosting server, and today I checked and it's been giving me this error every time i started up the bot.

client_secret.json-drive-v3-(['https://www.googleapis.com/auth/drive'],)
['https://www.googleapis.com/auth/drive']
Traceback (most recent call last):
  File "C:UsersUnknown1Documentsdiscordbotot.py", line 5, in <module>
    from googledrive import find_recent
  File "C:UsersUnknown1Documentsdiscordbotgoogledrive.py", line 10, in <module>
    service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
  File "C:UsersUnknown1DocumentsdiscordbotGoogle.py", line 28, in Create_Service
    cred.refresh(Request())
  File "C:UsersUnknown1AppDataLocalProgramsPythonPython39libsite-packagesgoogleoauth2credentials.py", line 200, in refresh
    access_token, refresh_token, expiry, grant_response = _client.refresh_grant(
  File "C:UsersUnknown1AppDataLocalProgramsPythonPython39libsite-packagesgoogleoauth2\_client.py", line 248, in refresh_grant
    response_data = _token_endpoint_request(request, token_uri, body)
  File "C:UsersUnknown1AppDataLocalProgramsPythonPython39libsite-packagesgoogleoauth2\_client.py", line 124, in _token_endpoint_request
    _handle_error_response(response_body)
  File "C:UsersUnknown1AppDataLocalProgramsPythonPython39libsite-packagesgoogleoauth2\_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.', '{
  "error": "invalid_grant",
  "error_description": "Token has been expired or revoked."
}')
PS C:UsersUnknown1Documentsdiscordbot>

I checked the client_secret_file.json and redownloaded it from google cloud api credentials and its still the same thing. I'm not sure where to go about from here to fix this issue.

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)

I have set up a new project , OAuth 2.0 Client ID Credentials, following this youtube video:https://www.youtube.com/watch?v=FAM_4J7ywcE&ab_channel=nouthemes

and deleted the old one in hopes of replacing the client secret file with the new one. Now I am getting a new error :

client_secret.json-drive-v3-(['https://www.googleapis.com/auth/drive'],)
['https://www.googleapis.com/auth/drive']
Traceback (most recent call last):
  File "C:UsersUnknown1Documentsdiscordbotot.py", line 5, in <module>
    from googledrive import find_recent
  File "C:UsersUnknown1Documentsdiscordbotgoogledrive.py", line 10, in <module>
    service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
  File "C:UsersUnknown1DocumentsdiscordbotGoogle.py", line 28, in Create_Service
    cred.refresh(Request())
  File "C:UsersUnknown1AppDataLocalProgramsPythonPython39libsite-packagesgoogleoauth2credentials.py", line 200, in refresh
    access_token, refresh_token, expiry, grant_response = _client.refresh_grant(
  File "C:UsersUnknown1AppDataLocalProgramsPythonPython39libsite-packagesgoogleoauth2\_client.py", line 248, in refresh_grant
    response_data = _token_endpoint_request(request, token_uri, body)
  File "C:UsersUnknown1AppDataLocalProgramsPythonPython39libsite-packagesgoogleoauth2\_client.py", line 124, in _token_endpoint_request
    _handle_error_response(response_body)
  File "C:UsersUnknown1AppDataLocalProgramsPythonPython39libsite-packagesgoogleoauth2\_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.', '{
  "error": "deleted_client",
  "error_description": "The OAuth client was deleted."
}')

I'm stuck.

question from:https://stackoverflow.com/questions/65894026/google-api-token-expired-or-revoked

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...