如何从Apps Domain用户获取包含自定义字段的Google个人资料信息?

Lou*_*cci 2 google-app-engine google-apps gdata google-apps-script

使用user.profile和user.email作用域以及/ oauth2/v2/userinfo feed似乎不会返回任何自定义字段(在我的案例中为Department)或电话号码.这些字段显示在"域共享联系人"目录中.

是否有类似于Apps域特定的供稿网址//oauth2/{DOMAIN}/v2/userinfo?

API /服务不支持任何自定义字段吗?

有没有办法将其捏造成工作?

对您自己的应用程序域共享联系人配置文件的读访问权限应该不会那么困难.

我更喜欢非管理员解决方案,因为我的域使用具有SAML身份验证的公共访问卡,所以我不能只在App Engine应用程序中存储管理员凭据(用户:密码)并访问/ m8/feed.如果有一个流程来访问具有预先授权的消费者密钥和秘密的域共享联系人(带有自定义字段),我会对使其工作的说明感兴趣.

编辑 Jay Lee钉了它" https://www.google.com/m8/feeds/gal/ {domain}/full"

以下是使用Google Apps脚本的概念验证脚本(我完成后会添加最终的OAuth2版本)

function getGal(email, passwd, domain) {
  var res = UrlFetchApp.fetch("https://www.google.com/accounts/ClientLogin", {
    contentType: "application/x-www-form-urlencoded",
    method: "post",
    payload: { "Email": email, "Passwd": passwd, "accountType": "HOSTED", "service":"cp" }
  });
  var auth = res.getContentText().match(/Auth=(.*)/i)[1];
  Logger.log("Auth: " + auth);
  res = UrlFetchApp.fetch("https://www.google.com/m8/feeds/gal/" + domain + "/full", {
    method: "get",
    headers: { "Authorization": "GoogleLogin auth=" + auth, "GData-Version": "1.0" }
  });
  Logger.log(res.getHeaders());
  Logger.log(res.getContentText());
}
Run Code Online (Sandbox Code Playgroud)

编辑2返回JSON的OAuth版本,仅返回访问脚本的用户的信息.

function googleOAuthM8() {
  var oAuthConfig = UrlFetchApp.addOAuthService("m8");
  oAuthConfig.setRequestTokenUrl('https://www.google.com/accounts/OAuthGetRequestToken?scope=https://www.google.com/m8/feeds/');
  oAuthConfig.setAuthorizationUrl('https://www.google.com/accounts/OAuthAuthorizeToken');
  oAuthConfig.setAccessTokenUrl('https://www.google.com/accounts/OAuthGetAccessToken');
  oAuthConfig.setConsumerKey('anonymous');
  oAuthConfig.setConsumerSecret('anonymous');
  return {oAuthServiceName:"m8", oAuthUseToken:'always'};
}
function getGal(domain) {
  res = UrlFetchApp.fetch("https://www.google.com/m8/feeds/gal/" + domain + "/full?alt=json&q=" + Session.getActiveUser().getEmail(), googleOAuthM8());
  Logger.log(res.getHeaders());
  Logger.log(res.getContentText());
}
Run Code Online (Sandbox Code Playgroud)

Jay*_*Lee 10

任何非管理员用户都可以通过编程方式访问GAL,请参阅:

https://github.com/google/gfw-deployments/blob/master/apps/shell/gal/gal_feed.sh

我不认为此API调用是正式记录或支持的,但它甚至可以使用OAuth身份验证而不是示例的ClientLogin(在具有非管理员用户和标准https://www.google.com/m8/feeds/Contacts范围的OAuth 2.0操场上测试).

请注意,全局地址列表是用户配置文件,组和共享联系人的汇编.您需要解析它以找到您希望获得部门信息的用户.