Get the documents list of a domain user

If you are the administrator of a Google Apps Account, then you can get the document list of a domain user. There is no direct interface to do this, but Docs List API allows you.

Refrences: 

Here is short Google Apps Script code which will get the document list of your domain user.

// To run this function, you must have administrator priviledge in your domain
// user = 'user@YourDomain.com'
//This function will return document ID, Document Title of all the documents

function getDocuments(user){
  var scope = 'https://docs.google.com/feeds/';
  //oAuth
  var fetchArgs = googleOAuth_('docs', scope);
  var url = scope + user+'/private/full?v=3&alt=json';
  var urlFetch = UrlFetchApp.fetch(url, fetchArgs);
  var json = Utilities.jsonParse(urlFetch.getContentText());
  var entry = json.feed.entry;
  var docs = [];
  for(var i in entry){
    var tempDoc = {};
    for(var j in entry[i]){
      tempDoc.id = entry[i].id.$t.split('%3A')[1];
      tempDoc.title = entry[i].title.$t;
    }
    docs.push(tempDoc);
  }
  return docs;
}

//--------------------------------------------------------------------------------------
//Google oAuth
//Used by getDocuments(user)
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"};
}
//--------------------------------------------------------------------------------------

Comments