我是API的新手。尝试从sharepoint中提取用户配置文件我使用以下代码但不知道servername?域名?和用户名?
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);
请指导我它会给我错误 {“属性或字段'UserProfileProperties'尚未初始化。尚未请求或请求尚未执行。可能需要明确请求。”} 在以下一行
clientContext.ExecuteQuery();
答案 0 :(得分:1)
最有可能的是它与accountName
变量的格式有关。 PeopleManager.GetPropertiesFor method期望i:0#.f|membership|jdow@contoso.onmicrosoft.com
参数以适当的格式指定,对于SharePoint Online,应以声明格式指定,例如:
targetUser
有关声明格式的详细信息,请点击this article。
因此,在您的情况下,ttgdev-my.sharepoint.com\\testuser1@ttgdev.guru
值应从i:0#.f|membership|testuser1@ttgdev.guru
替换为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);
}
以下示例演示了如何通过CSOM API检索用户个人资料图片:
{{1}}