朋友
我是我的域管理员,我很难使用配置API来收集帐户的所有属性,如下所示。
function myFunction() {
var base = "https://apps-apis.google.com/a/feeds/";
var fetchArgs = googleOAuth_("provisioning", base);
var url = base + "domain" + "/user/2.0";
var result = UrlFetchApp.fetch(url,fetchArgs).getContentText()
var xml = Xml.parse(result);
//Logger.log(result)
var users = xml.feed.entry;
var r = [['Usuário', 'Nome Completo', 'Permissão Administrador', 'Cota', 'Conta Bloqueada']];
for( var i in users )
r.push([users[i].login.userName,
users[i].name.givenName+' '+users[i].name.familyName,
users[i].login.admin,
users[i].quota.limit,
users[i].login.suspended]);
var s = SpreadsheetApp.getActiveSheet();
s.clearContents();
s.getRange(1, 1, r.length, r[0].length).setValues(r);
}
function googleOAuth_(name,scope) {
var oAuthConfig = UrlFetchApp.addOAuthService(name);
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey("anonymous");
oAuthConfig.setConsumerSecret("anonymous");
return {oAuthServiceName:name, oAuthUseToken:"always"};
}
是否有人知道告诉帐户属性,使用的示例配额,暂停帐户的日期。
答案 0 :(得分:0)
您是否尝试过UserManager服务?它非常易于使用且非常完整......至少对我来说它带给我的是我需要的东西; - )
这是它的工作原理(简化版,为了让更多参数使用users[i]
上的自动完成功能):
function findUsers(s) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
sheet.getDataRange().clear()
var users = UserManager.getAllUsers();
var r = new Array();
//
for( var i = 0 ; i < users.length ; i++ ){
var Umail = users[i].getEmail();
var UnomF = users[i].getFamilyName()
var UnomP = users[i].getGivenName()
// here you can add other parameters
if(users[i].getAgreedToTerms()){var Udejaconnect = 'oui'}else{var Udejaconnect = 'jamais'}
//
r.push([UnomF,UnomP,Umail,Udejaconnect]);
}
r.sort(function(x,y){
var xp = x[0];
var yp = y[0];
Logger.log(xp+' '+yp)
return xp == yp ? 0 : xp < yp ? -1 : 1;// sort on name ascending
}
)
var header = ['Nom de famille','Prénom','Email','Déjà Connecté?']
sheet.getRange(1,1,1,r[0].length).setValues([header]).setFontWeight('bold')
.setBackground('silver').setBorder(true,true,true,true,true,true);
sheet.getRange(2,1,r.length,r[0].length).setValues(r);
}
答案 1 :(得分:0)
这是返回意外错误的代码
function doGet()
{
var domain = "sac.sulamerica.com.br";
var date = "2012-06-24";
var typeReport = "accounts"
var XML = "<?xml version='1.0' encoding='UTF-8'?>"+
"<rest xmlns='google:accounts:rest:protocol'"+
"xmlns:xsi=' http://www.w3.org/2001/XMLSchema-instance '>"+
"<type>Report</type>"+
"<domain>"+domain+"</domain>"+
"<date>"+date+"</date>"+
//"<page>1</page>"+
"<reportType>daily</reportType>"+
"<reportName>"+typeReport+"</reportName>"+
"</rest>";
var scope = 'https://www.google.com/hosted/services/v1.0/reports/ReportingData';
var name = 'reporting';
var OAuth = getOAuth(name, scope);
// var headers = {
// oAuthServiceName:name,
// oAuthUseToken:"always",
// headers: { "Content-type":"application/xml; charset=UTF-8"},
// method:"POST",
// payload:XML};
OAuth.method = 'POST';
OAuth.payload = XML;
var response = UrlFetchApp.fetch(scope, OAuth).getContentText();
Logger.log(response);
var xml = Xml.parse(response);
Logger.log(result)
var users = xml.feed.entry;
var r = [['Usuário', 'Email', 'Nome Completo', 'Permissão Administrador', 'Cota', 'Conta Bloqueada', 'Cota Usada']];
for( var i in users )
r.push([users[i].login.userName,
users[i].login.userName+'@domain.com.br',
users[i].name.givenName+' '+users[i].name.familyName,
users[i].login.admin,
users[i].quota.limit,
users[i].login.suspended,
users[i].accounts.quotainmb]);
var s = SpreadsheetApp.getActiveSheet();
s.clearContents();
s.getRange(1, 1, r.length, r[0].length).setValues(r);
}
function getOAuth(name,scope) // gets an auth certificate from Google
{
// Logger.log('--Get OAuth--');
var oAuthConfig = UrlFetchApp.addOAuthService(name);
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey("anonymous");
oAuthConfig.setConsumerSecret("anonymous");
return {oAuthServiceName:name, oAuthUseToken:"always"};
}