Skip to main content
Tweeted twitter.com/#!/StackWebApps/status/431421466174038016
retagging
Link
Jacob Jan
  • 23.3k
  • 16
  • 106
  • 195
Source Link
Ronan
  • 147
  • 7

500 error with Google admin sdk

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)