【问题标题】:Get user profile by email using JSOM in SharePoint 2013 Online在 SharePoint 2013 Online 中使用 JSOM 通过电子邮件获取用户配置文件
【发布时间】:2014-11-23 11:12:00
【问题描述】:

我正在使用 JSOM 在 SP 2013 Online 中开发 SharePoint 托管应用程序。我的要求是使用电子邮件 ID 获取用户个人资料属性。 我知道我们可以使用输入作为帐户名称来获取任何用户个人资料,例如

userProfileProperty = peopleManager.getUserProfilePropertyFor(accountName, propertyName)

但是是否可以使用用户的电子邮件 ID 来做同样的事情?

【问题讨论】:

    标签: office365 sharepoint-online


    【解决方案1】:

    SP.UserProfiles.PeopleManager.getUserProfilePropertyFor 方法需要 accountName 参数以声明格式提供

    关于身份声明格式

    SharePoint 2013 和 SharePoint 2010 使用以下编码格式显示身份声明:

    <IdentityClaim>:0<ClaimType><ClaimValueType><AuthMode>|<OriginalIssuer (optional)>|<ClaimValue>
    

    请按照本文进行解释。

    对于 SharePoint Online (SPO),帐户使用以下格式:

    i:0#.f|membership|username@tenant.onmicrosoft.com 
    

    可以根据电子邮件地址构建声明:

    function toClaim(email)
    {
        return String.format('i:0#.f|membership|{0}',email);
    }
    

    示例

    var email = 'username@tenant.onmicrosoft.com'; 
    var profilePropertyName = "PreferredName";
    var accountName = toClaim(email);
    
    
    function getUserProfilePropertyFor(accountName,profilePropertyName,success,failure)
    {
       var context = SP.ClientContext.get_current();
       var peopleManager = new SP.UserProfiles.PeopleManager(context);
       var userProfileProperty = peopleManager.getUserProfilePropertyFor(accountName,profilePropertyName);
    
       context.executeQueryAsync(
       function(){
          success(userProfileProperty);
       }, 
       failure);
    }
    

    用法

    getUserProfilePropertyFor(accountName,profilePropertyName,
       function(property){
          console.log(property.get_value());
       }, 
       function(sender,args){
          console.log(args.get_message());    
       });
    

    参考文献

    SharePoint 2013: Claims Encoding

    【讨论】:

    • 非常感谢@Vadim 解决了我的疑问。我对帐户名称格式有疑问。您提到帐户名称的格式为 i:0#.f|membership|username@tenant.onmicrosoft.com。帐户名称是否始终以“.onmicrosoft.com”结尾?是否可以将其更改为 i:0#.f|membership|username@tenant.com?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-25
    相关资源
    最近更新 更多