Javascript Gapi drive.files.list响应仅显示文档

Javascript Gapi drive.files.list响应仅显示文档,javascript,api,google-api-js-client,Javascript,Api,Google Api Js Client,我正在后台脚本中使用GoogleDriveAPI,因此它可以与我的chrome扩展一起使用。我让身份验证工作正常,但我想知道为什么gapi响应只返回文档,而不返回文件夹 这是我的密码: manifest.json(用于扩展): { “清单版本”:2, “名称”:“思考。未来。劳动力。联系。”, “说明”:“一个扩展,允许教师从smartpath存储库中选择课程,并将其传输到他们的Google教室驱动器。”, “版本”:“0.0.1”, “浏览器操作”:{ “默认弹出窗口”:“index.html

我正在后台脚本中使用GoogleDriveAPI,因此它可以与我的chrome扩展一起使用。我让身份验证工作正常,但我想知道为什么gapi响应只返回文档,而不返回文件夹

这是我的密码: manifest.json(用于扩展):

{
“清单版本”:2,
“名称”:“思考。未来。劳动力。联系。”,
“说明”:“一个扩展,允许教师从smartpath存储库中选择课程,并将其传输到他们的Google教室驱动器。”,
“版本”:“0.0.1”,
“浏览器操作”:{
“默认弹出窗口”:“index.html”,
“默认标题”:“打开弹出窗口”
},
“背景”:{
“页面”:“background.html”,
“持续”:假
},
“图标”:{
“16”:“favicon.ico”,
“48”:“favicon.ico”,
“128”:“favicon.ico”
},
“密钥”:“密钥”,
“oauth2”:{
“客户id”:“,
“范围”:[
"https://www.googleapis.com/auth/drive.file"
]
},
“内容安全策略”:“脚本src'self”https://apis.google.com/;对象src'self';“,
“权限”:[
"https://vast-stream-39133.herokuapp.com/",
"https://www.googleapis.com/*",
“身份”
]
}
background.html:

<html>
 <head>
    <script src="https://apis.google.com/js/client.js?onload=onGAPILoad"></script>
  <title></title>
  <script src="background.js"></script>
 </head>
 <body></body>
 </script>
</html>

background.js:

// Client ID and API key from the Developer Console
var CLIENT_ID = '<my client id>';
var API_KEY = '<my api_key>';

// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"];

// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = 'https://www.googleapis.com/auth/drive.file';

/**
 *  On load, called to load the auth2 library and API client library.
 */

function handleClientLoad() {
  gapi.load('client:auth2', initClient);
}

handleClientLoad();
console.log('test');

/**
 *  Initializes the API client library and sets up sign-in state
 *  listeners.
 */
function initClient() {
    gapi.client.init({
      // Don't pass client nor scope as these will init auth2, which we don't want
      apiKey: API_KEY,
      discoveryDocs: DISCOVERY_DOCS,
    }).then(function () {
      console.log('gapi initialized')
      chrome.identity.getAuthToken({interactive: true}, function(token) {
        gapi.auth.setToken({
          'access_token': token,
          'fields': "nextPageToken, files(id, name)"
        }); 
        console.log(gapi.client.drive)
        gapi.client.drive.files.list({
            'pageSize': 1000,
          }).then(function(response, err) {
            var files = response;
            console.log(files);
            if (files && files.length > 0) {
            console.log(files)
            }
            if(err) {
                console.log(err);
            } 
            else {
              console.log('No files found.');
            }
          });
      })
    }, function(error) {
      console.log('error', error)
    });
  }
//来自开发人员控制台的客户端ID和API密钥
var客户端ID=“”;
var API_键=“”;
//quickstart使用的API的API发现文档URL数组
var DISCOVERY_DOCS=[”https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"];
//API要求的授权范围;可以使用多个作用域
//包含,用空格分隔。
var作用域https://www.googleapis.com/auth/drive.file';
/**
*加载时,调用以加载auth2库和API客户端库。
*/
函数handleClientLoad(){
load('client:auth2',initClient);
}
handleClientLoad();
console.log('test');
/**
*初始化API客户端库并设置登录状态
*听众。
*/
函数initClient(){
gapi.client.init({
//不要传递client或scope,因为它们将初始化auth2,这是我们不想要的
API密钥:API_密钥,
发现文档:发现文档,
}).然后(函数(){
console.log('gapi initialized')
chrome.identity.getAuthToken({interactive:true},函数(token){
gapi.auth.setToken({
“访问令牌”:令牌,
“字段”:“下一个GetOken,文件(id,名称)”
}); 
log(gapi.client.drive)
gapi.client.drive.files.list({
“页面大小”:1000,
}).then(功能(响应、错误){
var文件=响应;
console.log(文件);
如果(files&&files.length>0){
console.log(文件)
}
如果(错误){
控制台日志(err);
} 
否则{
log('未找到任何文件');
}
});
})
},函数(错误){
console.log('error',error)
});
}
运行background.html检查视图时:

我只想看到文件夹?有什么想法吗?当我对Node执行此命令时,不会发生这种情况

// Client ID and API key from the Developer Console
var CLIENT_ID = '<my client id>';
var API_KEY = '<my api_key>';

// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"];

// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = 'https://www.googleapis.com/auth/drive.file';

/**
 *  On load, called to load the auth2 library and API client library.
 */

function handleClientLoad() {
  gapi.load('client:auth2', initClient);
}

handleClientLoad();
console.log('test');

/**
 *  Initializes the API client library and sets up sign-in state
 *  listeners.
 */
function initClient() {
    gapi.client.init({
      // Don't pass client nor scope as these will init auth2, which we don't want
      apiKey: API_KEY,
      discoveryDocs: DISCOVERY_DOCS,
    }).then(function () {
      console.log('gapi initialized')
      chrome.identity.getAuthToken({interactive: true}, function(token) {
        gapi.auth.setToken({
          'access_token': token,
          'fields': "nextPageToken, files(id, name)"
        }); 
        console.log(gapi.client.drive)
        gapi.client.drive.files.list({
            'pageSize': 1000,
          }).then(function(response, err) {
            var files = response;
            console.log(files);
            if (files && files.length > 0) {
            console.log(files)
            }
            if(err) {
                console.log(err);
            } 
            else {
              console.log('No files found.');
            }
          });
      })
    }, function(error) {
      console.log('error', error)
    });
  }