且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

访问Google Drive API返回空文件列表

更新时间:2023-01-18 19:00:22

帐户以访问我自己的Google云端硬盘中的文件,我必须为服务帐户的电子邮件地址授予权限。一旦权限设置正确,该列表就会填充允许服务帐户访问的文件。

I'm testing out the Google Drive API. The test script does the HTTP GET to access the Files->List API but somehow I always get an empty list in items. I have hundreds of files in my google drive so the result is unexpected. The HTTP response is shown below.

    {
     "kind": "drive#fileList",
     "etag": "\"VEU5fga3uYlZRf0pG-N1kS4iWP4/Kxo5eGvPKynWfroe9v5L5T43-n0\"",
     "selfLink": "https://www.googleapis.com/drive/v2/files?maxResults=5",
     "items": []
    }

To allow service account to access the files in my own Google Drive, I have to give permission to the email address of the service account. Once the permissions are setup correctly, the list gets populated with the files that the service account is allowed to access.