2012-06-22 96 views
0

朋友API配置 - 屬性帳戶

我爲我的域管理員,我有一個很難得到收集帳戶的所有屬性,使用配置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

?我在我的域上測試了你的代碼,並且按預期工作......你還會得到錯誤嗎?現在由於你我有葡萄牙語標題; --D –

+0

但我會解決它,不要擔心;-)) –

+0

只是一件事:它只獲得100個結果。你在哪裏給這個參數? (現在我不再回答,但要求;-) –

回答

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); 
} 
+0

感謝您的幫助...我最大的需要是出口配額已被用作電子郵件,例如其他數據....是否有可能? –

+0

列表是[here](https://developers.google.com/apps-script/class_domainuser) –

+0

我的需要是瞭解用戶信息字段的屬性。我從Google api找到了一些網站,但是當我點擊Google網站訪問elemennto的屬性時,找不到錯誤頁面,請點擊鏈接:(https://developers.google.com/googleapps/domain/gdata_provisioning_api_v2 .0_reference.html#google_apps_tag_apps:quota) –

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"}; 
} 
+0

沒有人有任何想法如何解決?謝謝!! –