2

I am trying to write a Python program that makes a file in Google Drive. But if I try to do it, it says

'Your browser has been opened to visit:
()
    https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&response_type=code&client_id=742339009631-b7rv2mnplb22rhdjb1m663aken700cfe.apps.googleusercontent.com&access_type=offline
()'

Then it opens the browser and I get the following:

"
401. That’s an error.

Error: deleted_client

The OAuth client was deleted.

Request Details
scope=https://www.googleapis.com/auth/drive
redirect_uri=http://localhost:8080/
response_type=code
client_id=742339009631-b7rv2mnplb22rhdjb1m663aken700cfe.apps.googleusercontent.com
access_type=offline
That’s all we know."

Does Google have a newer version? Or what's the problem?

My code is:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
drive = GoogleDrive(gauth)

f = drive.CreateFile()
f.SetContentFile('hello.txt')
f.Upload()
print('title: %s, mimeType: %s' % (f['title'], f['mimeType']))

file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()

for file1 in file_list:
  print('title: %s, id: %s' % (file1['title'], file1['id']))

1 Answer 1

3

Based from Handling API Errors, an error code 401 indicates invalid credentials. This error is usually encountered due to invalid authorization header or the access token you're using is either expired or invalid.

Suggested action for such error is to refresh the access token using the long-lived refresh token. If this fails, direct the user through the OAuth flow, as described in Authorizing Your App with Google Drive.

Furthermore, "The OAuth client was deleted" error message was also displayed. You may want to check if there's an existing client ID. If none, you need to obtain new OAuth 2.0 credentials from the Google API Console. Here are the basic steps in Using OAuth 2.0 to Access Google APIs:

  1. Obtain OAuth 2.0 credentials from the Google API Console.
  2. Obtain an access token from the Google Authorization Server.
  3. Send the access token to an API.
  4. Refresh the access token, if necessary.

Lastly, you may want to also check the best practices in Handling errors: revoked or invalid tokens and also Token expiration so you can better anticipate the possibility that a granted token might no longer work.

Hope that helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.