获取暂停用户的文件
Fetch the files of suspended users
google 应用程序脚本中是否有一种方法可以根据 his/her 电子邮件 ID 获取已暂停所有者的文件?我实际上是在尝试实施 transfer drive files to a new owner using google apps script, I am using 以查找所有暂停用户的详细信息:
/**
* Fetches the suspended user details from the AdminDirectory.
*/
function fetchUser() {
// Set the constant options only once.
const options = {
domain: 'xyz.com',
orderBy: 'email',
query: 'isSuspended=true',
maxResults: 500,
fields: "nextPageToken,users"
};
// Could log the options here to ensure they are valid and in the right format.
const results = [];
do {
var search = AdminDirectory.Users.list(options);
// Update the page token in case we have more than 1 page of results.
options.pageToken = search.nextPageToken;
// Append this page of results to our collected results.
if(search.users && search.users.length)
Array.prototype.push.apply(results, search.users);
} while (options.pageToken);
//Logger.log(results);
for(var k = 0; k < results.length; k++){
var fullEmail = results[k].primaryEmail;
Logger.log(fullEmail);
fetchFiles(fullEmail);
}
}
/**
* Fetches the files of the suspended users based on their email.
*/
function fetchFiles(email){
var pageToken;
var filesList = Drive.Files.list({ // Invalid value error is thrown here, I am not sure if this the right way to use Drive API in google script
domain: 'xyz.com',
orderBy: 'email',
q: "'email' in owners",
maxResults: 500,
pageToken: pageToken
});
Logger.log('filesList:' +filesList);
}
我正在尝试实现类似 Transfer ownership of a file to another user in Google Apps Script 的东西,但是有什么方法可以让我从上面的代码中获得的详细信息中获取用户的文件,基本上是 returns 以下代码输出:
[
{
orgUnitPath = /,
ipWhitelisted = false,
gender = {type = other},
creationTime = 2017-06-13T14:38:44.000Z,
isMailboxSetup = true,
isEnrolledIn2Sv = false,
kind = admin#directory#user,
suspensionReason = ADMIN,
isAdmin = false,
suspended = true,
emails = [{
address = john.seb@xyz.com,
primary = true
}],
lastLoginTime = 2017-09-12T00:27:00.000Z,
isDelegatedAdmin = false,
isEnforcedIn2Sv = false,
changePasswordAtNextLogin = false,
customerId = v12idsa,
name = {
givenName = John,
familyName = Seb,
fullName = John Seb
},
etag = "npJcgeAc7Xbfksfwer22344/sfasdfaffUDsfdsjfhsfhsdfw-ec",
id = 1033392392142423424,
primaryEmail = john.seb@xyz.com,
agreedToTerms = true,
includeInGlobalAddressList = true
},
...
]
我正在尝试使用 google 应用程序脚本中的 Drive API 以便使用他们的电子邮件访问暂停用户的文件,但它抛出
"Invalid Value" error
对于行 Drive.Files.list
,我不确定这是否是在 google 脚本中使用 DRIVE API
的正确方法,还有其他方法可以使用这个 api 在 google 脚本中?
在您的函数 fetchFiles
中,您从不使用输入参数 email
。相反,您查询 Drive REST API 以获得文字文本 'email' in owners
。由于文本字符串 'email'
不是有效的电子邮件地址,您会正确收到错误消息 "Invalid value".
而不是这个代码:
/**
* Fetches the files of the suspended users based on their email.
*/
function fetchFiles(email){
var pageToken;
var filesList = Drive.Files.list({
domain: 'jerseystem.org',
orderBy: 'email',
q: "'email' in owners",
maxResults: 500,
pageToken: pageToken
});
Logger.log('filesList:' +filesList);
}
您应该首先执行替换,以设置所有常量选项(正如我在您的其他问题中提到和演示的那样),然后重复查询驱动器 API 以查找用户拥有的文件电子邮件地址:
function fetchAllFilesOwnedByEmail(email) {
const searchParams = {
corpora: 'some corpora',
orderBy: 'some ordering criteria',
q: "'" + email + "' in owners",
fields: 'nextPageToken,items(id,title,mimeType,userPermission)'
};
const results = [];
do {
var search = Drive.Files.list(searchParams);
if (search.items)
Array.prototype.push.apply(results, search.items);
searchParams.pageToken = search.nextPageToken;
} while (searchParams.pageToken);
return results;
}
您需要查看 Drive REST API 文档,如果没有,请参阅 Drive.Files.list
and Search for Files at minimum. Don't forget to enable the Drive
advanced service。
另请注意,虽然上面的代码将解决您遇到的 "Invalid Value"
错误,但它不一定会使用户的文件显示出来,即使您以 G-Suite 管理员身份执行代码也是如此.您的研究应该至少发现以下两个相关问题:
google 应用程序脚本中是否有一种方法可以根据 his/her 电子邮件 ID 获取已暂停所有者的文件?我实际上是在尝试实施 transfer drive files to a new owner using google apps script, I am using
/**
* Fetches the suspended user details from the AdminDirectory.
*/
function fetchUser() {
// Set the constant options only once.
const options = {
domain: 'xyz.com',
orderBy: 'email',
query: 'isSuspended=true',
maxResults: 500,
fields: "nextPageToken,users"
};
// Could log the options here to ensure they are valid and in the right format.
const results = [];
do {
var search = AdminDirectory.Users.list(options);
// Update the page token in case we have more than 1 page of results.
options.pageToken = search.nextPageToken;
// Append this page of results to our collected results.
if(search.users && search.users.length)
Array.prototype.push.apply(results, search.users);
} while (options.pageToken);
//Logger.log(results);
for(var k = 0; k < results.length; k++){
var fullEmail = results[k].primaryEmail;
Logger.log(fullEmail);
fetchFiles(fullEmail);
}
}
/**
* Fetches the files of the suspended users based on their email.
*/
function fetchFiles(email){
var pageToken;
var filesList = Drive.Files.list({ // Invalid value error is thrown here, I am not sure if this the right way to use Drive API in google script
domain: 'xyz.com',
orderBy: 'email',
q: "'email' in owners",
maxResults: 500,
pageToken: pageToken
});
Logger.log('filesList:' +filesList);
}
我正在尝试实现类似 Transfer ownership of a file to another user in Google Apps Script 的东西,但是有什么方法可以让我从上面的代码中获得的详细信息中获取用户的文件,基本上是 returns 以下代码输出:
[
{
orgUnitPath = /,
ipWhitelisted = false,
gender = {type = other},
creationTime = 2017-06-13T14:38:44.000Z,
isMailboxSetup = true,
isEnrolledIn2Sv = false,
kind = admin#directory#user,
suspensionReason = ADMIN,
isAdmin = false,
suspended = true,
emails = [{
address = john.seb@xyz.com,
primary = true
}],
lastLoginTime = 2017-09-12T00:27:00.000Z,
isDelegatedAdmin = false,
isEnforcedIn2Sv = false,
changePasswordAtNextLogin = false,
customerId = v12idsa,
name = {
givenName = John,
familyName = Seb,
fullName = John Seb
},
etag = "npJcgeAc7Xbfksfwer22344/sfasdfaffUDsfdsjfhsfhsdfw-ec",
id = 1033392392142423424,
primaryEmail = john.seb@xyz.com,
agreedToTerms = true,
includeInGlobalAddressList = true
},
...
]
我正在尝试使用 google 应用程序脚本中的 Drive API 以便使用他们的电子邮件访问暂停用户的文件,但它抛出
"Invalid Value" error
对于行 Drive.Files.list
,我不确定这是否是在 google 脚本中使用 DRIVE API
的正确方法,还有其他方法可以使用这个 api 在 google 脚本中?
在您的函数 fetchFiles
中,您从不使用输入参数 email
。相反,您查询 Drive REST API 以获得文字文本 'email' in owners
。由于文本字符串 'email'
不是有效的电子邮件地址,您会正确收到错误消息 "Invalid value".
而不是这个代码:
/**
* Fetches the files of the suspended users based on their email.
*/
function fetchFiles(email){
var pageToken;
var filesList = Drive.Files.list({
domain: 'jerseystem.org',
orderBy: 'email',
q: "'email' in owners",
maxResults: 500,
pageToken: pageToken
});
Logger.log('filesList:' +filesList);
}
您应该首先执行替换,以设置所有常量选项(正如我在您的其他问题中提到和演示的那样),然后重复查询驱动器 API 以查找用户拥有的文件电子邮件地址:
function fetchAllFilesOwnedByEmail(email) {
const searchParams = {
corpora: 'some corpora',
orderBy: 'some ordering criteria',
q: "'" + email + "' in owners",
fields: 'nextPageToken,items(id,title,mimeType,userPermission)'
};
const results = [];
do {
var search = Drive.Files.list(searchParams);
if (search.items)
Array.prototype.push.apply(results, search.items);
searchParams.pageToken = search.nextPageToken;
} while (searchParams.pageToken);
return results;
}
您需要查看 Drive REST API 文档,如果没有,请参阅 Drive.Files.list
and Search for Files at minimum. Don't forget to enable the Drive
advanced service。
另请注意,虽然上面的代码将解决您遇到的 "Invalid Value"
错误,但它不一定会使用户的文件显示出来,即使您以 G-Suite 管理员身份执行代码也是如此.您的研究应该至少发现以下两个相关问题: