Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Replace the following placeholder values with the target
- // server URL and target user.
- const string serverUrl = "http://serverName";
- const string targetUser = "domainName\userName";
- // Get the client context.
- clientContext = new ClientContext(serverUrl);
- // Get the SocialFeedManager instance.
- followingManager = new SocialFollowingManager(clientContext);
- // Create a SocialActorInfo object to represent the target user.
- SocialActorInfo actorInfo = new SocialActorInfo();
- actorInfo.AccountName = targetUser;
- // Find out whether the current user is following the target user.
- ClientResult<bool> isFollowed = followingManager.IsFollowed(actorInfo);
- // Get the information from the server.
- clientContext.ExecuteQuery();
- Console.WriteLine("Was the current user following the target user? {0}n", isFollowed.Value);
- Console.Write("Initial count: ");
- // Get the current count of followed people.
- WriteFollowedCount();
- // Try to follow the target user. If the result is OK, then
- // the request succeeded.
- ClientResult<SocialFollowResult> result = followingManager.Follow(actorInfo);
- clientContext.ExecuteQuery();
- // If the result is AlreadyFollowing, then stop following
- // the target user.
- if (result.Value == SocialFollowResult.AlreadyFollowing)
- {
- followingManager.StopFollowing(actorInfo);
- clientContext.ExecuteQuery();
- }
- // Handle other SocialFollowResult return values.
- else if (result.Value == SocialFollowResult.LimitReached
- || result.Value == SocialFollowResult.InternalError)
- {
- Console.WriteLine(result.Value);
- }
- // Get the updated count of followed people.
- Console.Write("Updated count: ");
- WriteFollowedCount();
- Console.ReadKey();
- }
- // Get the count of the people who the current user is following.
- static void WriteFollowedCount()
- {
- ClientResult<int> followedCount = followingManager.GetFollowedCount(SocialActorTypes.Users);
- clientContext.ExecuteQuery();
- Console.WriteLine("The current user is following {0} people.", followedCount.Value);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement