3

ドキュメントに記載されているとおりに行います:

#google key
API_key = "xxxxx"
#creating an instance of the class
drive_service = build('drive', 'v2', developerKey = API_key)
#get a list of child folder in
children = drive_service.children().list(folderId='yyyyyyy', **param).execute()

エラー:

エラーが発生しました: https://www.googleapis.com/drive/v2/files/yyyyyyy/children?alt=json&key=xxxxx が「ログインが必要です」を返しました">

私は何を間違っていますか?

4

2 に答える 2

3

これは、GDrive API V3 を使用したフォルダーの問い合わせを示す最小限のバージョンです。

import httplib2
import pprint
import sys
from apiclient.discovery import build

def printChildren(parent):
  param = {"q": "'" + parent + "' in parents and mimeType != 'application/vnd.google-apps.folder'"}
  result = service.files().list(**param).execute()
  files = result.get('files')

  for afile in files:
    print('File {}'.format(afile.get('name')))

API_KEY = 'XXXXXXX' # get from API->Credentials page in console.cloud.googl.com
FOLDER_ID = '1bWJ18tyq1h-ABQT79SgTsJQFRCIIblHS' # NOTE: folder must be publicly visible when using an API key.
service = build('drive', 'v3', developerKey=API_KEY)
printChildren(FOLDER_ID)
于 2020-11-28T19:04:30.330 に答える