Python & Google Drive 專案 — 2

yysu
2 min readJun 18, 2017

--

今日找到了一個好東西,讓我直接放棄看Google Drive Api,這個套件叫做`PyDrive`,直接放棄昨天的程式XD,用這個套件節省我好多時間,好了不說廢話該繼續了,今日的目標:能夠將檔案上傳。

先進到quickstart.py,把以下的程式碼複製貼上即可

name = 'yysu_cv.pdf'  # It's the file which you'll upload file = drive.CreateFile()  # Create GoogleDriveFile instance file.SetContentFile(name)  file.Upload()

再來執行,即可成功上傳。

Python quickstart.py

附上(quickstart.py完整程式碼):

from pydrive.auth import GoogleAuthfrom pydrive.drive import GoogleDriveimport sysgauth = GoogleAuth()gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication.drive = GoogleDrive(gauth)try:    name = 'yysu_cv.pdf'  # It's the file which you'll upload    file = drive.CreateFile()  # Create GoogleDriveFile instance    file.SetContentFile(name)    file.Upload()except :    print("Unexpected error:", sys.exc_info()[0])

--

--

yysu
yysu

Written by yysu

AWS Certified All-5 | CKA & CKAD | Ex - Cloud Engineer @ AWS

No responses yet