1

I am trying to use Google Apps Profiles Data API to retrieve profile information of Google Apps Users in my domain. Here us the code which I have tried so far but it is giving error Request failed for returned code 403. Server response: Version 1.0 is not supported. (line 7, file "Profile")

function getAllProfiles() {
  var scope = 'https://www.google.com/m8/feeds/profiles';
  var fetchArgs = googleOAuth_('Profile', scope);
  fetchArgs.method = 'GET';
  var domain = UserManager.getDomain();
  var url = scope+'/domain/'+domain+'/full';
  var rawData = UrlFetchApp.fetch(url, fetchArgs).getContentText();
  Logger.log(rawData);
}

//google oAuth
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"};
}

Note:

  • My account has super Admin access in Google Apps
  • I am trying this code with Google Apps Enterprise Edition

References: Google Apps Profile Data API

It will be great if someone can point me in right direction

Waqar Ahmad
  • 3,716
  • 1
  • 16
  • 27
  • Have you seen [this post](http://stackoverflow.com/questions/13717809/to-get-users-profile-information-in-google-script) ? I had success trying it. – Serge insas Mar 29 '13 at 07:27
  • 1
    @Sergeinsas Thanks for pointing to that link. I got my code working when I added a version parameter v=3 to the request URL – Waqar Ahmad Mar 29 '13 at 09:53

1 Answers1

3

Here is the modified code which needed a version parameter with the request URL. Now the code is working fine.

function getAllProfiles() {
  var scope = 'https://www.google.com/m8/feeds/profiles';
  var fetchArgs = googleOAuth_('Profile', scope);
  fetchArgs.method = 'GET';
  var domain = UserManager.getDomain();
  var url = scope+'/domain/'+domain+'/full?v=3';
  var rawData = UrlFetchApp.fetch(url, fetchArgs).getContentText();
  Logger.log(rawData);
}

//google oAuth
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"};
}
Waqar Ahmad
  • 3,716
  • 1
  • 16
  • 27