繁体   English   中英

将Google Apps配置文件API与Apps脚本一起使用

[英]Using Google Apps Profiles API with Apps Script

我正在尝试使用Google Apps配置文件数据API来检索我域中Google Apps用户的个人资料信息。 在这里我们到目前为止我尝试过的代码,但它给出了错误Request failed for returned code 403. Server response: Version 1.0 is not supported. (line 7, file "Profile") 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企业版试用此代码

参考: Google Apps Profile Data API

如果有人能指出我正确的方向,那将是很棒的

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM