4

我正嘗試在Google Apps腳本中使用雲端硬盤REST API讀取Google相冊。代碼如下所示:如何使用Drive Rest API讀取雲端硬盤照片

function myFunction() { 
    var files = Drive.Files.list({ 
    maxResults: 10, 
    spaces: 'photos'  
    }); 

    for (var i = 0; i < files.items.length; i++) { 
    var f = files.items[i]; 
    Logger.log(f.title); 
    } 
} 

但是,如果我運行這個功能谷歌顯示錯誤「(代碼

被准許的範圍不會將所有請求的空間給接入線路2,文件‘)’。」

Page with error enter image description here

項目屬性包含範圍 「https://www.googleapis.com/auth/drive」 - 即所有對象都應該是可用的。但由於某種原因,我得到這個錯誤。我認爲這是Google Apps腳本中的一個錯誤。有什麼想法嗎?

回答

2

照片實際上並不是Google Drive API V3其Picasa網絡相冊數據API的一部分,因爲您需要使用Picasa網絡相冊數據API範圍對其進行身份驗證。

https://picasaweb.google.com/data/

https://www.googleapis.com/auth/drive.photos.readonly

該範圍只需添加到您的腳本應該工作,然後你不能只

https://www.googleapis.com/auth/drive

+2

你能告訴如何在App腳本中需要這個特殊的作用域嗎?當例如我們在代碼中使用DriveApp時,應用腳本通常會自動要求作用域...但是如何手動要求特定作用域? – eshangin

+0

非常漂亮的看起來像那個範圍的作品。 – DaImTo

+0

另外,當我使用https://developers.google.com/drive/v3/reference/files/list#try上的空間'照片'調用Drive API時,它足以包含'https://www.googleapis。 com/auth/drive'範圍。 – eshangin

相關問題