2013-03-29 121 views
1

我试图使用Google Apps配置文件数据API检索我的域中的Google Apps用户的配置文件信息。在这里我们这是我迄今但它给错误Request failed for returned code 403. Server response: Version 1.0 is not supported. (line 7, file "Profile")通过Apps脚本使用Google Apps配置文件API

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"}; 
} 

注意试图代码:

  • 我的帐户在谷歌企业应用套件
  • 我试图与谷歌的代码超级管理员权限Google Apps企业版

参考文献: Google Apps Profile Data API

如果有人能指引我正确的方向,这将是很好的

+0

你见过[这篇文章](http://stackoverflow.com/questions/13717809/to-get-users-profile-information-in-google-script)吗?我尝试过成功。 –

+1

@Sergeinsas感谢您指向该链接。当我向请求URL添加版本参数v = 3时,我的代码正常工作 –

回答

3

这是修改后的代码,需要带请求URL的版本参数。现在代码工作正常。

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"}; 
}