12

PyDrive を使用して、Google ドライブ内のすべてのファイルのリストを取得しようとしています。ドキュメントを読み、すべての手順を完了しました。client secrets.json を保存しましたが、引き続き次のエラーが発生します。私が使用しているコードは次のとおりです。

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'])

私が得ているエラーは、これを修正するにはどうすればよいですか?

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

7 に答える 7

2

私も同じ問題を抱えていました。ログインできない理由は次のとおりです。

InvalidConfigError: 無効なクライアント シークレット ファイルファイルが見つかりません: "client_secrets.json"


認証情報ファイル名をclient_secret_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com.json

から
client_secrets.jsonに変更する必要があります。

乾杯、パパ

于 2015-10-01T08:36:27.543 に答える
2

まず、 https ://console.developers.google.com/project にアクセスします。

次に、プロジェクト -> Api と認証 -> 資格情報に移動します。ここで client_secrets.json をダウンロードできます。

このファイル (client_secrets.json) を、.py を実行しているのと同じディレクトリにコピーします。

于 2015-04-10T15:20:01.353 に答える
0

資格情報ファイルを既にダウンロードし、名前を "client_secrets.json" に変更し、スクリプトと同じフォルダーに保持しているにもかかわらず、このエラーが引き続き発生する場合は、以下を試すと役立つ場合があります。

import os 
print (os.getcwd()) # to check the current working directory, if the current working directory above is different than your folder containing the script then change the working directory to your script directory.

os.chdir('/script_directory_path') # replace '/script_directory_path' with your original script path, and place this code above 'gauth = GoogleAuth()' in your script.
于 2021-05-16T16:09:25.790 に答える