【问题标题】:Using Google Apps Profiles API with Apps Script将 Google Apps Profiles API 与 Apps 脚本结合使用
【发布时间】:2013-03-29 06:02:47
【问题描述】:

我正在尝试使用 Google Apps Profiles Data API 来检索我的域中 Google Apps 用户的个人资料信息。这是我迄今为止尝试过的代码,但它给出了错误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"};
}

注意:

  • 我的帐户在 Google Apps 中具有超级管理员权限
  • 我正在使用 Google Apps Enterprise Edition 尝试此代码

参考资料: Google Apps Profile Data API

如果有人能指出正确的方向,那就太好了

【问题讨论】:

  • 你见过this post 吗?我尝试成功了。
  • @Sergeinsas 感谢您指向该链接。当我将版本参数 v=3 添加到请求 URL 时,我的代码工作了

标签: google-apps-script


【解决方案1】:

这是修改后的代码,它需要带有请求 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"};
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-14
    • 2014-08-25
    • 2017-08-06
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    相关资源
    最近更新 更多