4

pydrive を使用して Google ドライブからファイルをダウンロードしようとしています。コードはpydrive 検証プロセスの自動化から変更されています

そして、次のエラーが発生しています。

$ python driveDownload.py a a.xls
Google Drive Token Expired, Refreshing
Traceback (most recent call last):
  File "driveDownload.py", line 26, in <module>
    gauth.Refresh()
  File "build/bdist.linux-x86_64/egg/pydrive/auth.py", line 369, in Refresh
pydrive.auth.RefreshError: No refresh_token found.Please set access_type of OAuth to offline.

したがって、ここでstackoverflowの指示に従いました

それを機能させることができません。基本的なものが欠けていますか?

私のsettings.yamlは以下です

client_config_backend: settings 
client_config:   
  client_id: ###
  client_secret: ###

save_credentials: True 
save_credentials_backend: file 
save_credentials_file: credentials.json

get_refresh_token: True

oauth_scope:
  - https://www.googleapis.com/auth/drive.file
  - https://www.googleapis.com/auth/drive.install

次のエラーが表示されます:

$ python driveDownload.py a a.xls
Google Drive Token Expired, Refreshing
Traceback (most recent call last):
  File "driveDownload.py", line 26, in <module>
    gauth.Refresh()
  File "build/bdist.linux-x86_64/egg/pydrive/auth.py", line 369, in Refresh
pydrive.auth.RefreshError: No refresh_token found.Please set access_type of OAuth to offline.

私のコードは driveDownload.py です:

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

#USAGE: python driveDownload.py googleDriveName localFileName
#authentication via the browser
#note... client_secrets.json is required for this that leads
#to the user authentication
fileName2Download = sys.argv[1]    
#myLocalPath is hard coded and 
myLocalPath = sys.argv[2]


# gauth = GoogleAuth()

gauth = GoogleAuth()
# Try to load saved client credentials
gauth.LoadCredentialsFile("GoogleDriveCredentials.txt")
if gauth.credentials is None:
    # Authenticate if they're not there
    gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
    # Refresh them if expired
    print "Google Drive Token Expired, Refreshing"
    gauth.Refresh()
else:
    # Initialize the saved creds
    gauth.Authorize()
# Save the current credentials to a file
gauth.SaveCredentialsFile("GoogleDriveCredentials.txt")

#accessing the drive
drive = GoogleDrive(gauth)


# Auto-iterate through all files that matches this query
file_list = drive.ListFile().GetList()
for file1 in file_list:
#download the file hello.txt ad myDownload.txt
    print 'title: %s, id: %s , mimeType = %s' % (file1['title'], file1['id'],file1['mimeType'])
    if file1['title'] == fileName2Download:
        print ' file Title identiefied :%s'% (file1['title']) 
#         contentString = file1.GetContentString()
#         print 'contentString : %s' % (contentString)
        myFile = drive.CreateFile({'id': file1['id']})
        if os.path.exists(myLocalPath):
            os.remove(myLocalPath)

        myFile.GetContentFile(myLocalPath,mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
        print '%s downloaded ' %(myLocalPath)
        break
4

0 に答える 0