在python中使用googleapiclient更新Google云端硬盘元数据

时间:2018-10-29 15:59:22

标签: google-api google-drive-api metadata

我正在尝试使用python的Google API客户端库在Google云端硬盘中更新测试文件的元数据(特别是文件名)。我已经使用了以下Google资源:

我没有遇到连接到Google Drive API的麻烦。我只是在更新文件名或我想更新的任何其他元数据时遇到问题。

我的代码如下:

delete from 
   location_in a
where 
  a.rowid > 
   any (
     select 
        B.rowid
     from 
        location_in b
     where 
        A.location_id = B.location_id);
commit;
from googleapiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools

from googleapiclient import errors
from googleapiclient.http import MediaFileUpload
# This is to connect to Google Drive's API

SCOPES = 'https://www.googleapis.com/auth/drive.metadata' #drive.metadata gives me the access to read and writeover metadata
CLIENT_SECRET = 'client_id.json' #this is from Oauth when you create credentials for a good project

store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets(CLIENT_SECRET, SCOPES)
    creds = tools.run_flow(flow, store)
DRIVE = discovery.build('drive', 'v3', http=creds.authorize(Http()))
files = DRIVE.files().list().execute().get('files', [])

print()
print("File Specific metadata")
for f in files:
    if f['name']=='Test' and f['mimeType']=='application/vnd.google-apps.document':
        print(f['name'], f['id'], f['mimeType'])
        file_id = f['id']
        print(file_id)

但是,当我这样做时,出现权限不足错误。我认为这与SCOPES有关,但我不确定。

0 个答案:

没有答案