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.

1 Answer 1

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("[email protected]", 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

1
  • The issue is with the use of access token in ClientContext. Have you verified the above with a ClientContext created using access token? Commented Sep 19, 2017 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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