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

梅迪·拉扎(Mehdi Raza)

我在项目中使用了react-native-google-drive-api-wrapper,可以成功登录并创建文件和文件夹,但无法列出存储在驱动器中的文件。我正在使用此链接中给出的react-native-google-drive-api-wrapper- https: //www.npmjs.com/package/react-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云端硬盘中存储的所有文件的列表。

梅迪·拉扎(Mehdi Raza)

我解决了 我认为这只是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.com/RobinBobin/react-native-google-drive-api-wrapper/issues/19#issue-571412310,我复制了他获取数据的方式。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何列出 Google Drive 根文件夹中的文件和文件夹

如何在Google Drive API上按文件夹获取文件列表

如何使用 Google Drive 获取请求文件/文件夹权限的用户列表

如何使用 PHP 和 Google Drive API 获取基于所有者的所有文件夹和文件

从React Native从共享文件夹导入

React-Native 导航文件夹

如何不检测在 google drive changes api 中打开文件和文件夹

如何使用react-native和expo获取位于assets文件夹中的文件的绝对路径?

Google Drive API-获取文件列表,包括文件夹

如何从react-native中的Assets文件夹中读取文件?

如何从React Native ios项目中的components文件夹访问js文件

如何通过 Google Apps Script 获取文件夹内 Google Drive 文件的“可共享链接”?

使用 react-native-google-drive-api-wrapper 将文件上传到 Google Drive 时出现 403

使用@访问React Native中的某些文件夹

没有redux的react native app的文件夹结构

当前文件夹中的react-native init

React-Native 不导入文件夹

减少 react native ios/android 大小文件夹

Android Google Drive SDK-如何显示所选文件夹中的文件列表

在Swift 3中获取Google Drive iOS基本目录中的文件夹列表吗?

未使用 Google Drive API 获取共享文件夹中的项目列表

如何在React Native项目中重新生成ios文件夹?

如何从react native中的主题文件夹导入可重用组件?

如何在React Native Fs中重命名/移动文件夹?

如何在React Native中访问其他文件夹中的资产?

如何在realm-react-native中创建嵌套的类似于文件夹的结构?

React native:安装react-native-maps后不存在android文件夹

使用.Net列出Google Drive V2中的所有文件和文件夹

在构建 React Native 项目时获取 react-native-google-signin:compileReleaseJavaWithJavac FAILED