Javascript google drive api-列出应用程序中与我共享的文件,仅对应用程序创建的文件具有读写权限(权限auth/drive.file)
我正在测试如何与Google API共享文件我已经掌握了如何与他人共享文件据我所知,这些文件是通过用户权限共享的,这是我通过应用程序所需要的,就共享文件的人而言,我看不到该文件,因为我注意到api没有在应用程序的驱动器中查询文件的读取权限,只需将权限设置为“”,因为我只希望我的应用程序能够访问她创建的文件 所有者(api中的列表)-->共享-->用户(非api中的列表)Javascript google drive api-列出应用程序中与我共享的文件,仅对应用程序创建的文件具有读写权限(权限auth/drive.file),javascript,google-drive-api,Javascript,Google Drive Api,我正在测试如何与Google API共享文件我已经掌握了如何与他人共享文件据我所知,这些文件是通过用户权限共享的,这是我通过应用程序所需要的,就共享文件的人而言,我看不到该文件,因为我注意到api没有在应用程序的驱动器中查询文件的读取权限,只需将权限设置为“”,因为我只希望我的应用程序能够访问她创建的文件 所有者(api中的列表)-->共享-->用户(非api中的列表) /////////代码共享文件所有者 var request1=gapi.client.request({ “路径”:“/d
/////////代码共享文件所有者
var request1=gapi.client.request({
“路径”:“/drive/v3/files/”+fileId+“/permissions”,
'method':'POST',
“标题”:{
“内容类型”:“应用程序/json”,
“授权”:“持票人”+sTokenDrive
},
“身体”:{
“角色”:“作者”,
“类型”:“用户”,
“电子邮件地址”:user@gmail.com'
}
});
请求1.执行(功能(resp){
控制台日志(resp);
});
////////代码列表文件用户
/**
*drive.files.list的JavaScript代码示例
*请参阅本地运行API Explorer代码示例的说明:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
函数身份验证(){
返回gapi.auth2.getAuthInstance()
.signIn({范围:https://www.googleapis.com/auth/drive.file"})
.then(function(){console.log(“登录成功”);},
函数(err){console.error(“错误登录”,err);});
}
函数loadClient(){
返回gapi.client.load(“https://content.googleapis.com/discovery/v1/apis/drive/v3/rest")
.then(function(){console.log(“为API加载的GAPI客户端”);},
函数(err){console.error(“为API加载GAPI客户端时出错”,err);});
}
//在调用此方法之前,请确保已加载客户端并完成登录。
函数execute(){
返回gapi.client.drive.files.list({
“语料库”:“用户”,
“q”:“sharedWithMe=true”
})
.然后(功能(响应){
//在这里处理结果(response.result具有解析的主体)。
控制台日志(“响应”,响应);
},
函数(err){console.error(“executeerror”,err);});
}
load(“客户端:auth2”,函数(){
init({client_id:'client_id'});
});
授权加载
执行
用户通过访问控制列表控制其他人访问其文件,表示为每个文件的一个列表。在Google Drive中共享写或读权限后,用户会显示它,但应用程序不会列出它,除非它通过访问驱动器的所有文件更改授予应用程序的权限。这意味着我们必须在“Drive.file”旁边添加“Drive.readonly”以检查“与我共享”的所有内容,多么可笑,至少起作用了
/////////CODE SHARED FILE OWNER
var request1 = gapi.client.request({
'path': '/drive/v3/files/' + fileId + '/permissions',
'method': 'POST',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + sTokenDrive
},
'body':{
'role': 'writer',
'type': 'user',
'emailAddress' : 'user@gmail.com'
}
});
request1.execute(function(resp) {
console.log(resp);
});
////////CODE LIST FILE USER
<script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for drive.files.list
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
function authenticate() {
return gapi.auth2.getAuthInstance()
.signIn({scope: "https://www.googleapis.com/auth/drive.file"})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
return gapi.client.load("https://content.googleapis.com/discovery/v1/apis/drive/v3/rest")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.drive.files.list({
"corpus": "user",
"q": "sharedWithMe = true"
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: 'CLIENT_ID'});
});
</script>
<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>