如何从Apps Domain用户获取包含自定义字段的Google个人资料信息? [英] How to get Google profile info including custom fields from an Apps Domain user?

查看:1527
本文介绍了如何从Apps Domain用户获取包含自定义字段的Google个人资料信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用user.profile和user.email作用域和/ oauth2 / v2 / userinfo提要似乎不会返回任何自定义字段(在我的部门中)或电话号码。这些字段显示在域名共享联系人目录中。



是否有像/ oauth2 / {DOMAIN} / v2 / userinfo这样的Apps域特定供稿网址? p>

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

有没有办法让这个工作变得有效?

阅读您自己的与您的帐户相关联的Apps Domain共享联系人配置文件应该不会那么困难。



我更喜欢非管理员解决方案,因为我的网域使用带有SAML身份验证的通用访问卡,因此我不能仅将管理凭据(用户名:密码)存储在一个App Engine应用程序并访问/ m8 / feed。如果有一个流程访问域共享联系人(具有自定义字段)与事先授权的消费者密钥和秘密,我会感兴趣的指示,让它工作。



编辑杰伊李钉住了它 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,
header:{Authorization:GoogleLogin auth =+ auth,GData-Version:1.0}
});
Logger.log(res.getHeaders());
Logger.log(res.getContentText());
}

编辑2 仅返回JSON的OAuth版本
$ b

  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'};
}
函数getGal(域){
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());


解决方案

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

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



我不认为这个API调用是正式记录或支持的,但它甚至可以使用OAuth身份验证而不是示例的ClientLogin(在OAuth 2.0游乐场中使用非管理员用户和标准 https://www.google.com/m8/feeds/ 通讯录范围)。



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


Using the user.profile and user.email scope and the /oauth2/v2/userinfo feed doesn't seem to return any custom fields (in my case Department) or phone numbers. These fields show up in the Domain Shared Contacts directory.

Is there perhaps an Apps Domain specific feed URL something like /oauth2/{DOMAIN}/v2/userinfo ?

Does the API/Service not support any custom fields yet?

Is there a way to fudge this into working?

Read access to your own Apps Domain Shared Contacts profile that's connected to your account shouldn't be so difficult.

I'd prefer a non-admin solution because my domain uses Common Access Cards w/ SAML authentication so I can't just store admin credentials (user : password) in an App Engine app and access the /m8/ feed. If there's a flow to access Domain Shared Contacts (with custom fields) with a beforehand authorized consumer key and secret I'd be interested in the instructions for getting that to work.

EDIT Jay Lee nailed it "https://www.google.com/m8/feeds/gal/{domain}/full"

Here's the proof of concept script using Google Apps Script (I'll add the final OAuth2 version when I finish it)

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());
}

EDIT 2 OAuth version that returns JSON and only the info for the user accessing the script.

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());
}

解决方案

Any non-admin user can access the GAL programmatically, see:

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

I don't believe this API call is documented or supported officially but it works even with OAuth authentication rather than the example's ClientLogin (tested on the OAuth 2.0 playground with a non-admin user and the standard https://www.google.com/m8/feeds/ Contacts scope).

Note that the Global Address List is a compilation of user profiles, groups and shared contacts. You'll need to parse it out to find the user(s) you wish to get department information for.

这篇关于如何从Apps Domain用户获取包含自定义字段的Google个人资料信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆