如何查看谷歌驱动器API的文件和文件夹? [英] How to see files and folder of google drive API?

查看:305
本文介绍了如何查看谷歌驱动器API的文件和文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



它不需要任何auth2认证,因为它是一个服务器服务器通信,用户不参与该过程。



这工作正常,但为什么它不使用我的帐户驱动器?
如果我创建一个文件夹或文件,我不能在谷歌驱动器中看到它,所以这是使用不同的存储,如果是这样,我有办法看到我的所有文件和文件夹像正常谷歌驱动器帐户?



我使用nodeJs,到目前为止这工作:

  var google = require('googleapis'); 
var drive = google.drive('v3');
var config = require('../ config / config');
var jwtClient = new google.auth.JWT(config.google.drive.client_email,null,config.google.drive.private_key,['https://www.googleapis.com/auth/drive'],null );

jwtClient.authorize(function(err,tokens){
if(err){
console.log(err);
return;
}

//发出授权请求以列出云端硬盘文件
//drive.files.create({
// auth:jwtClient,
//资源:{
// mimeType:'application / vnd.google-apps.folder',
// title:'my new folder
//}
//},函数(err,response){
// if(err){
// console.log('gdrive creat folder: '+ err);
//} else {
// console.log('create response:');
//}
//});

drive.files.list({auth:jwtClient},function(err,resp){
//处理错误和响应
console.log('err',err );
console.log('resp',resp);
});
});


解决方案

我假设您指的是服务帐户用于服务器到服务器的交互。



自从进入服务帐户的配置用户以来,它不会进入您的帐户。您可以将全域权限委派给服务帐户,但前提是您拥有Google Apps for Work


I created a google project, and setup all I need to use google drive API with JWT crementials.

It doesn't need any auth2 authentification since it's a server-server communication, user are not involved in the process.

This is working fine but why it's not using my account drive? If I create a folder or a file, I can"t see it in google drive, so is this using a different storage, and if so, do I have a way to see all my files and folder like a normal google drive account?

I'm using nodeJs and so far this worked :

var google = require('googleapis');
var drive = google.drive('v3');
var config = require('../config/config');
var jwtClient = new google.auth.JWT(config.google.drive.client_email, null, config.google.drive.private_key, ['https://www.googleapis.com/auth/drive'], null);

jwtClient.authorize(function(err, tokens) {
    if (err) {
        console.log(err);
        return;
    }

    // Make an authorized request to list Drive files.
    //drive.files.create({
    //    auth: jwtClient,
    //    resource: {
    //        mimeType: 'application/vnd.google-apps.folder',
    //        title: 'my new folder'
    //    }
    //},function(err,response){
    //    if(err){
    //        console.log('error at gdrive creat folder: ' + err);
    //    }else{
    //        console.log('create response: ');
    //    }
    //});

    drive.files.list({ auth: jwtClient }, function(err, resp) {
        // handle err and response
        console.log('err', err);
        console.log('resp', resp);
    });
});

解决方案

I'm assuming you're referring to Service Account for the server-to-server interaction.

Its not going in your account since its going to the Service Account's configured user. You can delegate the domain-wide authority to the Service Account but only if you have Google Apps for Work

这篇关于如何查看谷歌驱动器API的文件和文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆