首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React-原生Google Drive如何获取文件和文件夹列表

React-原生Google Drive如何获取文件和文件夹列表
EN

Stack Overflow用户
提问于 2020-04-23 01:40:06
回答 1查看 845关注 0票数 0

我已经在我的项目中使用了react-native-google- drive -api-wrapper,我可以成功登录并创建文件和文件夹,但我无法列出存储在我的驱动器中的文件。我正在使用这个链接中给出的react-native-google-drive-api-wrapper -- https://www.npmjs.com/package/react-native-google-drive-api-wrapper,来获取文件和文件夹的列表,上面链接中提到的代码是:

代码语言:javascript
复制
     GDrive.files.list({q: "'root' in parents"});

我的代码是:

代码语言:javascript
复制
     GDrive.files.list({q: "'root' in parents"})
             .then(response =>{ alert("response is "+JSON.stringify(response))
                  console.log(response.url)                      
            })
             .catch(er=> alert("error is" +er));

我得到的回答是,

代码语言:javascript
复制
     {"type":"default","status":200,"ok":true,"headers":{"map":{"content-securi
     ty-policy":"frame-ancestors 'self'","content-type":"application/json; charset=UT
     F-8","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","vary":"O
     rigin, X-Origin","date":"Wed, 22 Apr 2020 17:31:18 GMT","cache-control":"private
     , max-age=0, must-revalidate, no-transform","server":"GSE","alt-svc":"quic=\":44
     3\"; ma=2592000; v=\"46,43\",h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2
     592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\
     "; ma=2592000,h3-T050=\":443\"; ma=2592000","x-xss-protection":"1; mode=block","
     expires":"Wed, 22 Apr 2020 17:31:18 GMT"}},"url":"https://www.googleapis.com/dri
     ve/v3/files?q=%27root%27%20in%20parents","_bodyInit":{"_data":{"size":654,"offse
     t":0,"blobId":"7dbd3276-ae80-4e6e-85bd-04e2766787b7","__collector":{}}},"_bodyBl
     ob":{"_data":{"size":654,"offset":0,"blobId":"7dbd3276-ae80-4e6e-85bd-04e2766787
     b7","__collector":{}}}}      

我该如何获取存储在Google Drive中的所有文件的列表。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-23 02:03:27

我解决了。我认为这只是JSON.stringify(响应)和res.json()的区别。不管怎样,你可以使用下面的代码

代码语言:javascript
复制
    GDrive.files.list({
              q: "'root' in parents",
             })
              .then(res=>res.json())
              .then(data=>alert(data.files[1].name)) //data.files is the array containing list of files 
              .catch(err=>console.log(err))

多亏了https://github.com/RobinBobin/react-native-google-drive-api-wrapper/issues/19#issue-571412310,我复制了他获取数据的方式。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61371574

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档