我如何从共享点中提取个人资料图片

How can i Pull Profile image from sharepoint

我是 API 的新手并试图从共享点提取用户配置文件我使用以下代码但不知道服务器名称?域名?和用户名?

const string serverUrl = "http://sharepoint.com/";
            const string targetUser = "ttgdev-my.sharepoint.com\testuser1@ttgdev.guru";

            // Connect to the client context.
            ClientContext clientContext = new ClientContext(serverUrl);

            // Get the PeopleManager object and then get the target user's properties.
            PeopleManager peopleManager = new PeopleManager(clientContext);
            PersonProperties personProperties = peopleManager.GetPropertiesFor(targetUser);

            // Load the request and run it on the server.
            // This example requests only the AccountName and UserProfileProperties
            // properties of the personProperties object.
            clientContext.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties);
            clientContext.ExecuteQuery();

            foreach (var property in personProperties.UserProfileProperties)
            {
                Console.WriteLine(string.Format("{0}: {1}",
                    property.Key.ToString(), property.Value.ToString()));
            }
            Console.ReadKey(false);

请指导我它会给我错误 {"The property or field 'UserProfileProperties' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested."} 在下一行

 clientContext.ExecuteQuery();

很有可能与targetUser变量的格式有关。 PeopleManager.GetPropertiesFor method 期望 accountName 参数以正确的格式指定,如果是 SharePoint Online,则应以声明格式指定,例如:

i:0#.f|membership|jdow@contoso.onmicrosoft.com

For more details about Claims format follow this article.

因此,在您的情况下,targetUser 值应从 ttgdev-my.sharepoint.com\testuser1@ttgdev.guru 替换为 i:0#.f|membership|testuser1@ttgdev.guru


以下示例演示如何通过 CSOM 检索用户个人资料图片API:

using (var ctx = TokenHelper.GetClientContextWithAccessToken(webUri.ToString(), accessToken))
{

    // Get the PeopleManager object and then get the target user's properties.
    var peopleManager = new PeopleManager(ctx);
    PersonProperties personProperties = peopleManager.GetPropertiesFor(targetUser);

   //Retrieve picture property
   var result = peopleManager.GetUserProfilePropertyFor(accountName, "PictureURL");
   ctx.ExecuteQuery();
   Console.WriteLine("Picture Url: {0}",result.Value);
}