Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

SharePoint Online - Manipulate User Profiles from Azure WebJob

$
0
0

I've created an Azure WebJob to update users' profile.

I'd like to do this without providing credentials in the code. I've created a Principal with FullControl permissions to the User Profiles Scope but the job failed because of permissions.

The Code:

string UserAccountName = "i:0#.f|membership|user@tenant.com";
            string tenantAdministrationUrl = "https://tenant-admin.sharepoint.com/";
            Uri siteUri = new Uri(tenantAdministrationUrl);
            string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);
            string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;

            using (var clientContext = TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), accessToken))
            {
                // Get the people manager instance for tenant context
                PeopleManager peopleManager = new PeopleManager(clientContext);

                // Update the AboutMe property for the user using account name.
                peopleManager.SetSingleValueProfileProperty(UserAccountName, "AboutMe", "Update from CSOM");

                clientContext.ExecuteQuery();
            }

The Error:

Unhandled Exception: Microsoft.SharePoint.Client.ServerUnauthorizedAccessException: Access denied. You do not have permission to perform this action or access this resource.


Viewing all articles
Browse latest Browse all 7589

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>