PyDrive: Invalid Client Secrets File

I'm trying to use PyDrive to get a list of all the files in my Google Drive. I read the documents and followed all the steps. I have the secrets.json client stored, but I keep getting the following error. The code I'm using is:

from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive gauth = GoogleAuth() gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication drive = GoogleDrive(gauth) 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']) 

The error I get, how can I fix it?

 Traceback (most recent call last): File "C:\Users\mydrive\Documents\Python\Google_Drive.py", line 5, in <module> gauth.LocalWebserverAuth() File "build\bdist.win-amd64\egg\pydrive\auth.py", line 67, in _decorated self.GetFlow() File "build\bdist.win-amd64\egg\pydrive\auth.py", line 345, in GetFlow self.LoadClientConfig() File "build\bdist.win-amd64\egg\pydrive\auth.py", line 294, in LoadClientConfig self.LoadClientConfigFile() File "build\bdist.win-amd64\egg\pydrive\auth.py", line 314, in LoadClientConfigFile raise InvalidConfigError('Invalid client secrets file %s' % error) InvalidConfigError: Invalid client secrets file File not found: "client_secrets.json" 
+6
source share
3 answers

Based on the error log, your program cannot find the file: 'client_secrets.json'. This file is necessary because it helps identify your program in the Google API.

Steps for authentication:

  • Request access to the Google Drive API through the Google Cloud Console

    The steps described in: https://pythonhosted.org/PyDrive/quickstart.html

    I copy and update the instructions from the original page if the site is unavailable in the future:

    Google Drive API Access Instructions

    Go to the Google Developers Console - https://console.developers.google.com and create a new project

    Click Enable and Manage API , click API Driver , then click Enable API .

    In the API manager, click "Credentials" in the left pane. Select Add Credentials , select the OAuth 2.0 Client ID , then Web Application . You may need to set up a consent screen where the required part is the name of the product and the rest can be left blank.

    In the Create Client ID window with the web application selected as the application type, specify the Name for your application, put http://localhost:8080 to generate Javascript and http://localhost:8080/ for the redirect URI. IMPORTANT: One of these ends is with /, the other is not.

  • Download client_secrets.json from the Google Developers Console

    Go to the Google Developers Console - https://console.developers.google.com and find the Use the Google API section and click "Enable." and manage the API. Select Credentials in the left pane. You should see a list of OAuth 2.0 client identifiers. Disable the one you created in step 1, and click the JSON download button (looks like a down arrow icon). Rename the downloaded file to client_secrets.json.

  • Put client_secrets.json in the project directory

    It is best to place the downloaded client_secrets.json file in the same directory as your python program, which has the following line: gauth.LocalWebserverAuth ()

Once you get the authentication, I would recommend that you use the code from the answer fooobar.com/questions/165781 / ... to save the credentials so that you do not need to authenticate every time you run your code.

For more advanced users, you can create a settings.yaml file with advanced methods for saving credentials. Examples described in test files for the PyDrive project: https://github.com/googledrive/PyDrive/tree/master/pydrive/test I would like to mention that this advanced material is not needed so that everything is in order, everything that you need is the three steps explained in this answer.

+5
source

First go to: https://console.developers.google.com/project

then go to your project -> Apis and authentication -> credentials. Here you can download client_secrets.json.

Copy this file (client_secrets.json) to the same directory as your .py

+2
source

I had the same problem. The reason you cannot log in is here:

InvalidConfigError: Invalid client secrets file. File not found : "client_secrets.json"

You need to change the credential file name:
client_secret_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com.json



to:
client_secrets.json

Cheers, daddy

+2
source

Source: https://habr.com/ru/post/981639/


All Articles