使文件夹共享谷歌驱动器api v3? [英] make folder shared google drive api v3?

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

问题描述

我可以使用此代码创建一个文件夹

  var request = gapi.client.request({
' path':'/ drive / v3 / files /',
'method':'POST',
'headers':{
'Content-Type':'application / json'

//'Authorization':'Bearer'+令牌
},
'body':{
name:copy,
mimeType:application / vnd.google-apps.folder,


});


request.execute(function(resp){
console.log(resp);
//document.getElementById(\"info\").innerHTML =创建文件夹:+ resp.title;
});

但我不知道如何让文件夹共享给所有人,我看过在文档中输入类型:任何人,但我无法弄清楚如何在代码中做到这一点,感谢您的时间

解决方案

使用此REST函数为文件或文件夹创建权限:

  POST https:/ /www.googleapis.com/drive/v3/files/fileId/permissions 

所以你可以这样做:

  var fileId =文件ID; 
var request = gapi.client.request({$ b $'path':'/ drive / v3 / files /'+ fileId +'/ permissions',$ b $'method':'POST' ,
'headers':{
'Content-Type':'application / json'
//'授权':'持有人'+令牌
},
'body':{
'role':'reader',//所有者,作者,评论者
'type':'任何人'
}
});

如果成功,它会为您提供权限资源:

  {
kind:drive#permission,
id:唯一标识符
type:string,
emailAddress:string,
domain:string,
role:string,
allowFileDiscovery:布尔值,
displayName:string,
photoLink:string
}

我给你指向引用的链接,但是我还没有找到任何示例: p>


  • 共享文件/文件夹

  • 创建权限

  • 权限资源


  • I can make a folder using this code

    var request = gapi.client.request({
           'path': '/drive/v3/files/',
           'method': 'POST',
           'headers': {
               'Content-Type': 'application/json'
    
               //'Authorization': 'Bearer ' + token             
           },
           'body':{
               "name" : "copy",
               "mimeType" : "application/vnd.google-apps.folder",
    
           }
       });
    
    
       request.execute(function(resp) { 
           console.log(resp); 
           //document.getElementById("info").innerHTML = "Created folder: " + resp.title;
       });
    

    but I cant figure out for the life of me how to make the folder shared to all, I seen in the documentation to put type:anyone but I cant figure out how to do it in the code, thank you for your time

    解决方案

    You create a permission for a file or folder with this REST function:

    POST https://www.googleapis.com/drive/v3/files/fileId/permissions
    

    So you can do:

    var fileId = File Id;
    var request = gapi.client.request({
       'path': '/drive/v3/files/' + fileId + '/permissions',
       'method': 'POST',
       'headers': {
           'Content-Type': 'application/json'
           //'Authorization': 'Bearer ' + token             
       },
       'body':{
            'role': 'reader', // owner, writer, commenter
            'type': 'anyone'
       }
    });
    

    If it's successful, it'll give you a Permissions resource as a result:

    {
        kind: "drive#permission",
        id: Unique identifier,
        type: string,
        emailAddress: string,
        domain: string,
        role: string,
        allowFileDiscovery: boolean,
        displayName: string,
        photoLink: string
    }
    

    I give you links to the reference, but I haven't found any example there:

    这篇关于使文件夹共享谷歌驱动器api v3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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