久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Pydrive 谷歌驅動器自動身份驗證

Pydrive google drive automate authentication(Pydrive 谷歌驅動器自動身份驗證)
本文介紹了Pydrive 谷歌驅動器自動身份驗證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有以下代碼:

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.

問題是在谷歌瀏覽器中生成了一個驗證碼,每次用戶需要復制->將其粘貼到控制臺中以進行身份??驗證.有沒有辦法自動化這個過程?

The problem is that a verification code is generated in the Google Chrome and every time user needs to copy->paste it in the console in order to authenticate. Is there a way to automate this process?

推薦答案

其實需要將client_secret.json文件復制到my_cred.txt中,代碼如下:

Actually you need to copy the client_secret.json file to my_cred.txt by the following code:

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

然后使用以下代碼初始化驅動:

Then use the following code to initialize the drive:

def authorize_drive():
    gauth = GoogleAuth()
    gauth.DEFAULT_SETTINGS['client_config_file'] = "client_secret.json"
    gauth.LoadCredentialsFile("mycreds.txt")
    return GoogleDrive(gauth)


class DriveReport(object):
    def __init__(self):
        self.drive = authorize_drive()    

查看更多此鏈接:自動化pydrive驗證過程

這篇關于Pydrive 谷歌驅動器自動身份驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節點)
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 日本在线你懂的 | 亚洲欧洲一区二区 | 免费看黄视频网站 | 成人免费黄色 | 亚洲精品久久久一区二区三区 | 91在线最新 | 好婷婷网| 成年人网站在线观看视频 | 久久婷婷国产香蕉 | 国产精品日韩一区 | 天天成人综合网 | 国产一区二区三区高清 | 欧美在线资源 | 欧美久久久久久 | 色综合一区二区三区 | 国产在线一区二 | 黄色大片免费网站 | 日韩视频福利 | 一区二区三区视频 | 亚洲精品久久久久国产 | 中文字幕精品视频 | 欧美日韩高清在线一区 | 亚洲狠狠丁香婷婷综合久久久 | 亚洲欧美国产毛片在线 | 亚洲精彩视频在线观看 | 精品国产女人 | 成人激情免费视频 | 日韩在线视频一区二区三区 | 国产日韩中文字幕 | 一区二区三区高清 | 午夜久久久久久久久久一区二区 | 夜夜爽夜夜操 | 欧美成人精品激情在线观看 | 国产91丝袜在线熟 | 久久神马 | 网址黄| 亚洲人成人网 | 日韩午夜在线观看 | 久久国产成人精品国产成人亚洲 | 91在线网站 | 久久福利电影 |