1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PyDriveでGoogle Driveにアクセスしていーく(Windows 10、Python3.6)

Posted at

はじめに

PyDriveを使ってGoogle Driveにアクセスしていくー

開発環境

  • Windows 10 PC
  • Python 3.6

実装

1.ライブラリをインストール

conda activate py36
pip install PyDrive

2.Google Drive APIの有効化
image.png

3.認証情報からOAuth 2.0 クライアント IDを作成。
client_secret_xxxx-yyyy.apps.googleusercontent.com.jsonをダウンロード。

4.settings.yamlを作成

settings.yaml
client_config_file: client_secret_xxxx.json
save_credentials: True
save_credentials_backend: file
save_credentials_file: saved_credentials.json
get_refresh_token: True

5.下記プログラムを実行

test.py
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
drive = GoogleDrive(gauth)

file = drive.CreateFile({'title' : 'test.txt',
            'parents' : [{'id' : 'xxxx'}]})
file.SetContentString("Hello World !\n")
file.Upload()

※parentsのidにはgoogle driveのfoldersのidを入れる
https://drive.google.com/drive/u/0/folders/xxxx

6.初回のみGoogleの認証が出るので許可する
image.png

7.指定したフォルダにファイルが作成されていたら成功
image.png

お疲れ様でした。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?