Google Apps Script – Adding Company Directory with Pictures to Google Sites

google-apps-scriptgoogle-sites

I'm using this code to pull the name and emails of my users into an intranet page on Google Sites. I was just wondering, is there some code that I can add to this so I can retrieve pictures? I would imagine it goes in below flexTable.setWidget(parseInt(i), 1, app.createLabel(user.getEmail())); but I'm not sure what I can add there to retrieve their picture from their profile. I would also like to do the same for phone number.

function doGet() {
  var app = UiApp.createApplication(); 
  var users = UserManager.getAllUsers();  
  var flexTable = app.createFlexTable().setBorderWidth(1);

  for (var i=0, len=users.length; i<len; i++) {
    var user = users[i];
    flexTable.setWidget(parseInt(i), 0, app.createLabel(user.getGivenName()
      + ' ' + user.getFamilyName()));
    flexTable.setWidget(parseInt(i), 1, app.createLabel(user.getEmail()));
  }
  app.add(flexTable);
  return app;
}

Edit: I tried adding flexTable.setWidget(parseInt(i), 2, app.createLabel(user.getPhones())); but that gives me an error in the code. I got this from the API reference for scripts.

Best Answer

That's not possible I'm afraid with the API used. The API that's being used doesn't allow for more (basic) info to be retrieved.

There's however a new API released under Google Apps Script that can help you out:
Admin SDK Directory Service

This allows for much more tweaking !!