콘솔워크

[Python] 구글 드라이브 API로 폴더 만들어보기 본문

프로그래밍/python

[Python] 구글 드라이브 API로 폴더 만들어보기

이휘재123 2022. 6. 14. 13:50
반응형

https://uipath.tistory.com/134

 

[Python] 구글 드라이브 API 연결해보기

https://uipath.tistory.com/133 [Python] 구글 드라이브 API 초기설정 https://console.cloud.google.com/ Google 클라우드 플랫폼 로그인 Google 클라우드 플랫폼으로 이동 accounts.google.com 구글 클라우드..

uipath.tistory.com

위 링크의 설정이 필요합니다.

 

 

구글드라이브에 폴더를 생성하는 코드입니다.

 

 

from Google import Create_Service

CLIENT_SECRET_FILE = 'client_secret.json' # 초기설정 json파일 이름
API_NAME = 'drive'
API_VERSION = 'v3'
SCOPES = ['https://www.googleapis.com/auth/drive']

service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)

# 폴더 생성 테스트
folders = ['folder1', 'folder2', 'folder3']

for folder in folders:
    file_metadata = {
        'name': folder,
        'mimeType': 'application/vnd.google-apps.folder'
    }

    service.files().create(body=file_metadata).execute()

 

 

코드를 실행하면 드라이브에 폴더가 생성됩니다.

반응형