1

I am trying to get favorite sites of a user from SharePoint Online using CSOM. I am creating a ClientContext first using an access token and then trying to get the favorite sites using below code:

        try
        {
            ClientContext clientContext = this.GetSharePointClientContext(accessToken);
            SocialFollowingManager followingManager = new SocialFollowingManager(clientContext);               

            // Get the count of sites that the current user is following.
            ClientResult<int> followedSiteCount = followingManager.GetFollowedCount(SocialActorTypes.Sites);

            // Get the sites that the current user is following.
            ClientResult<SocialActor[]> followedSiteResult = followingManager.GetFollowed(SocialActorTypes.Sites);

            // Get the information from the server.
            clientContext.ExecuteQuery();
        }
        catch (Exception)
        {               
            throw;
        }

I am not able to find the root cause of this issue. Everything else seem to be working fine except getting favorite sites. Need help in resolving this issue.

0

I tested the code in my local, it’s working.

using (ClientContext clientContext = new ClientContext("https://xxx.sharepoint.com/sites/Lee"))
        {
            string password = "pw";
            SecureString sec_pass = new SecureString();
            Array.ForEach(password.ToArray(), sec_pass.AppendChar);
            sec_pass.MakeReadOnly();
            clientContext.Credentials = new SharePointOnlineCredentials("lee@xxx.onmicrosoft.com", sec_pass);

            SocialFollowingManager followingManager = new SocialFollowingManager(clientContext);

            // Get the count of sites that the current user is following.
            ClientResult<int> followedSiteCount = followingManager.GetFollowedCount(SocialActorTypes.Sites);

            // Get the sites that the current user is following.
            ClientResult<SocialActor[]> followedSiteResult = followingManager.GetFollowed(SocialActorTypes.Sites);

            // Get the information from the server.
            clientContext.ExecuteQuery();

            Console.ReadKey();
        }

enter image description here

  • The issue is with the use of access token in ClientContext. Have you verified the above with a ClientContext created using access token? – Saket Sep 19 '17 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.