1

I'm using the Admin SDK with Google Apps Script to create a directory of user's names and emails on a Google Site. The code seems to work fine because when I view the logs I see the results.

[14-02-04 12:24:05:996 GMT] Joe Ardee ([email protected])
[14-02-04 12:24:05:997 GMT] The Headmaster ([email protected])
[14-02-04 12:24:05:997 GMT] Edward Smith([email protected])

After I publish it as a web app and add it to my page using the insert scripts function I get a 500 error, on the page I get a message saying Google Drive encountered an error. When I published the app I set it so that only I can access it. I have also enabled the API and enable API access in the admin console.

Here is the code I am using;

function listAllUsers() {
  var users = AdminDirectory.Users.list({domain: 'example.com'}).users;
  if(users.length != 0) {
    for (var i=0; i<users.length; i++) {
      var user = users[i];
      Logger.log('%s (%s)', user.name.fullName, user.primaryEmail, user.phones);
    }
  } else {
    Logger.log('No users found.');
  }
}

(Instead of example.com in domain I have used the correct domain)

1

1 Answer 1

1

That's because it needs a whole different approach. Use the following code.

Code

function doGet(e) {
  var app = UiApp.createApplication();
  var flex = app.createFlexTable();  

  var users = AdminDirectory.Users.list({domain: 'jacobjantuinstra.nl'}).users;
  if(users.length != 0) {
    for (var i=0; i<users.length; i++) {
      var user = users[i];
      flex.setWidget(i, 0, app.createLabel(user.name.fullName))
      flex.setWidget(i, 1, app.createLabel(user.primaryEmail));
    }
  } else {
    flex.setWidget(0, 0, app.createLabel('No users found.'));
  }
  app.add(flex);

  return app;
}
5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.