0
我有以下Python
代碼:沒有本地服務器pydrive認證 - Python的
#!/usr/bin/env python
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
# Try to load saved client credentials
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
# Authenticate if they're not there
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
# Refresh them if expired
gauth.Refresh()
else:
# Initialize the saved creds
gauth.Authorize()
# Save the current credentials to a file
gauth.SaveCredentialsFile("mycreds.txt")
drive = GoogleDrive(gauth)
file1 = drive.CreateFile({'title': 'Hello3.txt'})
# Create GoogleDriveFile instance with title 'Hello.txt'
file1.SetContentString('Hello World!') # Set content of the file from given string
file1.Upload()
# Auto-iterate through all files that matches this query
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'])
的mycreds.txt
格式爲:
client_id = "foobarbaz.apps.googleusercontent.com"
client_secret = "foobarbaz"
不過,我每次執行該腳本時,本地服務器仍然出現了一個手動認證。我的目標是自動化該部分,因此用戶無需點擊授權按鈕。 我在做什麼錯?