Google Drive API客戶端(Python):對(duì)files()。insert()的權(quán)限不足
文件:insert需要具有以下至少一個(gè)作用域的授權(quán)
https://www.googleapis.com/auth/drivehttps://www.googleapis.com/auth/drive.filehttps://www.googleapis.com/auth/drive.appdatahttps://www.googleapis .com / auth /drive.apps.readonly
檢查您要使用哪個(gè)范圍進(jìn)行身份驗(yàn)證。
解決方法我正在嘗試使一個(gè)簡(jiǎn)單的Python Google Drive上傳器正常工作。我已經(jīng)在開發(fā)人員控制臺(tái)中創(chuàng)建了一個(gè)項(xiàng)目,啟用了DriveAPI,并添加了OAuth 2.0客戶端ID(應(yīng)用程序類型“其他”)。
我可以在Google云端硬盤的“設(shè)置”->“管理應(yīng)用”中看到該應(yīng)用程序,并且可以成功執(zhí)行Google的Python DriveAPI客戶端提供的許多操作。files().insert()但是失?。?/p>
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&convert=false&useContentAsIndexableText=false&alt=json returned 'Insufficient Permission'>
這是為了插入到我已使所有人可寫的目錄中,如下所示:
credentials = get_credentials ()http = credentials.authorize (httplib2.Http ())service = discovery.build (’drive’,’v2’,http=http)PARENT_ID='0B1gLgXwTiUzlfmo0UGVsZ1NWdW1nZG9OcENNYkJua2E1d0pqWE14TjFyc2hVMHdEU1h5czQ'perms = service.permissions().list(fileId=PARENT_ID).execute()print ('PERMISSIONS:')for perm in perms['items']: for p in perm:print (p,perm[p])printparent = { 'isRoot': False,'kind': 'drive#parentReference','id': PARENT_ID}service.files ().insert ( body = {'parents' : [parent]},media_body=’./test.txt’,convert=False,useContentAsIndexableText=False).execute ()
其中列出的權(quán)限為:
(u’withLink’,True)(u’kind’,u’drive#permission’)(u’etag’,u’'F-w0rsCIWtQP8RGyv_V1DlKfcRk/icwHkDdfUYuMzqZrUsVIyvu85K8'’)(u’role’,u’writer’)(u’type’,u’anyone’)(u’id’,u’anyoneWithLink’)(u’selfLink’,u’https://www.googleapis.com/drive/v2/files/0B1gLgXwTiUzlfmo0UGVsZ1NWdW1nZG9OcENNYkJua2E1d0pqWE14TjFyc2hVMHdEU1h5czQ/permissions/anyoneWithLink’)
任何人都可以指出我所缺少的權(quán)限嗎?
相關(guān)文章:
1. 教你JS更簡(jiǎn)單的獲取表單中數(shù)據(jù)(formdata)2. 用xslt+css讓RSS顯示的跟網(wǎng)頁一樣漂亮3. 《CSS3實(shí)戰(zhàn)》筆記--漸變?cè)O(shè)計(jì)(一)4. ASP.NET泛型三之使用協(xié)變和逆變實(shí)現(xiàn)類型轉(zhuǎn)換5. 測(cè)試模式 - XSL教程 - 56. 讓chatgpt將html中的圖片轉(zhuǎn)為base64方法示例7. html5手機(jī)觸屏touch事件介紹8. CSS3實(shí)現(xiàn)動(dòng)態(tài)翻牌效果 仿百度貼吧3D翻牌一次動(dòng)畫特效9. ASP.NET Core自定義中間件的方式詳解10. ASP.NET MVC把數(shù)據(jù)庫中枚舉項(xiàng)的數(shù)字轉(zhuǎn)換成文字
