我正在尝试GoogleAuth
使用该pydrive
库(https://pypi.python.org/pypi/PyDrive)自动化该过程.
我已经设置了pydrive和google API,以便我的secret_client.json
工作,但每次运行我的脚本时都需要对gdrive访问进行Web身份验证:
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
textfile = drive.CreateFile()
textfile.SetContentFile('eng.txt')
textfile.Upload()
print textfile
drive.CreateFile({'id':textfile['id']}).GetContentFile('eng-dl.txt')
Run Code Online (Sandbox Code Playgroud)
eng.txt
只是一个文本文件.此外,当我登录到另一个帐户时,我尝试使用上面的脚本.它不会上传eng.txt
到生成我的gdrive secret_client.json
但是我授权身份验证时登录的帐户
从上一篇文章中,我尝试了以下内容来自动执行验证过程,但它给出了错误消息:
import base64, httplib2
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
#gauth = GoogleAuth()
#gauth.LocalWebserverAuth()
# from google API console - convert …
Run Code Online (Sandbox Code Playgroud) 我有以下代码:
from pydrive.auth import GoogleAuth
gauth = GoogleAuth()
gauth.DEFAULT_SETTINGS = {'save_credentials': True,'client_config_backend': 'settings',
'oauth_scope': ['https://www.googleapis.com/auth/drive'],
'get_refresh_token': True,
'save_credentials_file':"credential_log.txt",
'save_credentials_backend': 'file'}
gauth.client_config = {'client_id': '499039293801-krogpnentl6qk035vt4hcd36nefiautt.apps.googleusercontent.com', 'client_secret': 'iqFCuOh36amMFi3U1dkyCWJK',
'redirect_uri':'urn:ietf:wg:oauth:2.0:oob','revoke_uri': 'None',
'token_uri':'https://accounts.google.com/o/oauth2/token',
'auth_uri':'https://accounts.google.com/o/oauth2/auth',
'save_credentials_file':"mycreds_p2iman.txt"}
gauth.CommandLineAuth()
from pydrive.drive import GoogleDrive
drive = GoogleDrive(gauth)
file4 = drive.CreateFile({'title':'somethingdifferent.txt', 'mimeType':'different/txt'})
file4.SetContentString('My name is John')
file4.Upload() # Upload file.
file4.SetContentString('My name is John')
file4.Upload() # Update content of the file.
Run Code Online (Sandbox Code Playgroud)
问题是在Google Chrome中生成验证码,并且每次用户需要复制 - >将其粘贴到控制台中以进行身份验证.有没有办法自动化这个过程?