![](/img/trans.png)
[英]SharePoint Online - Update User Profile Properties via CSOM App
[英]Azure Function Updating user profile using SharePoint Online and CSOM .NET Standard gives access denied
我有 Azure Function v3,我想使用全局管理員帳戶憑據更新帶有 CSOM 和 .NET 標准 2.0 的 Sharepoint 用戶配置文件屬性。 閱讀是有效的。
var site = new Uri("https://domain-admin.sharepoint.com");
using (var authenticationManager = new AuthenticationManager())
using (var context = authenticationManager.GetContext(site, user, password))
{
var peopleManager = new PeopleManager(context);
var personProperties = peopleManager.GetPropertiesFor(accountName);
context.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties);
await context.ExecuteQueryAsync();
Console.WriteLine(personProperties.UserProfileProperties["FirstName"]); //works
peopleManager.SetSingleValueProfileProperty(personProperties.AccountName, "FirstName", "CSOMvalue");
await context.ExecuteQueryAsync(); //error, access denied
}
確切的錯誤消息:System.Private.CoreLib:執行函數時出現異常:FunctionName。 Microsoft.SharePoint.Client.Runtime:拒絕訪問。 您無權執行此操作或訪問此資源。
AuthenticationManager 類取自此處的MS 文檔,我使用 Microsoft.SharePointOnline.CSOM v16.1.20518.12000 nuget 包。
我制作了 .NET Framework 4.7.2 Web 應用程序,它使用 SharePointOnlineCredentials 工作。 但我想知道如何讓它在 .NET Standard 2.0 上運行。
根據我過去的經驗和幾個小時的研究:
使用 Azure AD 應用程序時,可以通讀用戶配置文件 - 但不能執行 CSOM 寫入操作。
盡管文章說它適用於僅使用應用程序,但通常已觀察到 Azure AD 應用程序(用戶 + 應用程序也是如此)的這種行為 - 因此您可以讀取但不能寫入的原因。
正如文章中提到的,您必須僅使用Sharepoint App上下文並執行讀/寫操作。
context = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, "[Your Client ID]", "[Your Client Secret]")
這里的 authenticationmanager 屬於 SharepointPNPcoreOnline 庫。
本文詳述相同。
如果您在執行相同操作時想要用戶上下文(通常不需要,因為您在 UPA 執行) - 您可以相應地創建應用程序 - 但真的不確定 SharepointPNPCOreOnline 是否支持這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.