2013-03-29 123 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"}; 
}