谷歌驱动器api未捕获错误

时间:2014-02-25 10:21:18

标签: javascript google-drive-api

我的代码存在问题,我使用了google drive api文档

我收到此错误:

Uncaught TypeError: Cannot read property 'length' of undefined test.php:57
(anonymous function) test.php:57
(anonymous function) cb=gapi.loaded_0:631
Lm.Wy cb=gapi.loaded_0:629
(anonymous function) cb=gapi.loaded_0:629
(anonymous function) cb=gapi.loaded_0:143
_.T.E.__cb cb=gapi.loaded_0:69
g cb=gapi.loaded_0:63
c

但是我似乎无法看到我的代码出了什么问题:S

function retrieveAllFilesInFolder(folderId, callback) {     
            var retrievePageOfChildren = function(request, result) {
                request.execute(function(resp) {

                    for(var i=0; i<resp.items.length;i++){
                        result += (resp.items[i].id);
                        printFile(resp.items[i].id);
                    }

                    var nextPageToken = resp.nextPageToken;

                    if (nextPageToken) {
                        request = gapi.client.drive.children.list({
                        'folderId' : folderId,
                        'pageToken': nextPageToken,     
                    });
                    retrievePageOfChildren(request, result);
                    }else {
                        callback(result);
                    }
                });
            }
            var initialRequest = gapi.client.drive.children.list({
                'folderId' : folderId,
                'q' : "trashed = false and mimeType = 'application/vnd.google-apps.spreadsheet' and fullText contains 'walkthrough'"
            });
            retrievePageOfChildren(initialRequest, []);
        }

错误指向我的for循环

for(var i=0; i<resp.items.length;i++){

1 个答案:

答案 0 :(得分:0)

验证后

您可以使用以下功能从Google云端硬盘中检索文件

 function retrieveAllFilesInFolder() {
                debugger
                          gapi.client.load('drive', 'v2', function () {
                        var request = gapi.client.drive.files.list();
                        request.execute(function (resp) {
                            for (i = 0; i < resp.items.length; i++) {
                                var titulo = resp.items[i].title;
                                var fechaUpd = resp.items[i].modifiedDate;
                                var userUpd = resp.items[i].lastModifyingUserName;
                                var Id = resp.items[i].id;
                                var userAltLink = resp.items[i].alternateLink;
                                var userDownload = resp.items[i].webContentLink;
                                var type = resp.items[i].mimeType;
                                var chaneltype = resp.items[i].channelType;
                                var cId = resp.items[i].channelId;
                                var CAddress = resp.items[i].channelAddress;
                                var RId = resp.items[i].resourceId;
                                var MetaData = resp.items[i].fileMetadata;
                                var Data = resp.items[i]
        //                        alert(Data);
                                var fileInfo = document.createElement('div');
                               var Title = document.getElementById('content').appendChild(fileInfo);

                            }
                        });
                     });
                }

以及此

的Html
<p>
        <b>These are files from your GDrive :)</b></p>
    <div id="content">
    </div>