React-native Google Drive如何获取文件和文件夹列表?

问题描述 投票:0回答:1

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

     GDrive.files.list({q: "'root' in parents"});

我的代码是:

     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));

我得到的回应是:

     {"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中存储的所有文件的列表。

react-native google-drive-api
1个回答
1
投票

我解决了这个问题。我认为这只是JSON.stringify(response)和res.json()的不同。

    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.comRobinBobinreact-native-google-drive-api-wrapperissues19#issue-571412310。 我复制了他获取数据的方法。

© www.soinside.com 2019 - 2024. All rights reserved.