protected void Page_Load(object sender, EventArgs e) { var contextToken = TokenHelper.GetContextTokenFromRequest(Page.Request); var hostWeb = Page.Request["SPHostUrl"]; using (var clientContext = TokenHelper.GetClientContextWithContextToken(hostWeb, contextToken, Request.Url.Authority)) { SocialFollowingManager m = new SocialFollowingManager(clientContext); ClientResult <SocialActor[]> f1 = m.GetFollowed(SocialActorTypes.All); ClientResult <SocialActor[]> f2 = m.GetFollowers(); ClientResult <SocialActor[]> f3 = m.GetSuggestions(); clientContext.ExecuteQuery(); DumpList("Followed List", f1.Value); DumpList("Follower List", f2.Value); DumpList("Suggestion List", f3.Value); } }
public async Task<ActionResult> Network() { dynamic model = new ExpandoObject(); List<FavoriteSitesModel> favorites = new List<FavoriteSitesModel>(); List<GroupedVisitsModel> visited = new List<GroupedVisitsModel>(); string email = string.Empty; SharePointContext sharePointContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); using (ClientContext clientContext = sharePointContext.CreateUserClientContextForSPHost()) { if (clientContext != null) { email = GetCurrentUserEmail(clientContext); SocialFollowingManager followingManager = new SocialFollowingManager(clientContext); ClientResult<SocialActor[]> followed = followingManager.GetFollowed(SocialActorTypes.Sites); clientContext.ExecuteQuery(); foreach (var item in followed.Value.Take(5)) { favorites.Add(new FavoriteSitesModel() { SiteTitle = item.Name, WebAbsoluteUrl = item.ContentUri }); } } } if (!string.IsNullOrEmpty(email)) { visited = await (from v in db.Visits where v.UserLoginName == email group v by new { v.SiteTitle, v.WebAbsoluteUrl } into g select new GroupedVisitsModel { SiteTitle = g.Key.SiteTitle, WebAbsoluteUrl = g.Key.WebAbsoluteUrl, VisitCount = g.Count() } ).OrderByDescending(g=>g.VisitCount).Take(5).ToListAsync(); var chartbase = visited.Max(b => b.VisitCount); foreach (var item in visited) { item.VisitPercentage = (((float)item.VisitCount / (float)chartbase) * (float)100).ToString() + "px"; } } model.Visited = visited; model.Favorites = favorites; return View(model); }
private void ClientGuan() { ClientContext clientContext = new ClientContext(txtSiteUrl.Text); NetworkCredential cc = new NetworkCredential("userb", "123456", "ccc"); clientContext.Credentials = cc; SocialFollowingManager followingManager = new SocialFollowingManager(clientContext); SocialActorInfo actorInfo = new SocialActorInfo(); actorInfo.ContentUri = txtDocUrl.Text; actorInfo.ActorType = SocialActorType.Site; //string accountName = SPContext.Current.Web.CurrentUser.LoginName; //accountName = accountName.Substring(accountName.LastIndexOf("|") + 1); //actorInfo.AccountName = accountName; ClientResult <bool> isFollowed = followingManager.IsFollowed(actorInfo); clientContext.ExecuteQuery(); if (isFollowed.Value == true) { //If the user already following you can stop following by calling the StopFollowing() method. followingManager.StopFollowing(actorInfo); clientContext.ExecuteQuery(); //des.Text =accountName+ " StopFollowing OK"; } else { //If the user is not follwing then you can follow by using the Follow() method. followingManager.Follow(actorInfo); clientContext.ExecuteQuery(); //des.Text = accountName + " Follow OK"; } //}); //} //} //catch (Exception ex) //{ // //des.Text += des.Text + ex.ToString(); //} }
private List <SocialUser> LoadSocialUsers(SocialUserType type, SocialUserFilter filter) { List <SocialUser> users = new List <SocialUser>(); using (ClientContext ctx = TokenHelper.GetClientContextWithContextToken(hdnHostWeb.Value, hdnContextToken.Value, Request.Url.Authority)) { //Get social users ClientResult <SocialActor[]> socialActors = null; SocialFollowingManager followingManager = new SocialFollowingManager(ctx); ctx.Load(followingManager); if (type == SocialUserType.Follower) { socialActors = followingManager.GetFollowers(); } if (type == SocialUserType.Followed) { socialActors = followingManager.GetFollowed(SocialActorTypes.Users); } ctx.ExecuteQuery(); //Build a collection of users foreach (var socialActor in socialActors.Value) { SocialUser user = new SocialUser(); user.AccountName = socialActor.AccountName; user.Name = socialActor.Name; user.ImageUrl = socialActor.ImageUri; users.Add(user); } } //Filter the users return(FilterFollowed(users, filter)); }
private List<SocialUser> LoadSocialUsers(SocialUserType type, SocialUserFilter filter) { List<SocialUser> users = new List<SocialUser>(); using (ClientContext ctx = TokenHelper.GetClientContextWithContextToken(hdnHostWeb.Value, hdnContextToken.Value, Request.Url.Authority)) { //Get social users ClientResult<SocialActor[]> socialActors = null; SocialFollowingManager followingManager = new SocialFollowingManager(ctx); ctx.Load(followingManager); if (type == SocialUserType.Follower) socialActors = followingManager.GetFollowers(); if (type == SocialUserType.Followed) socialActors = followingManager.GetFollowed(SocialActorTypes.Users); ctx.ExecuteQuery(); //Build a collection of users foreach (var socialActor in socialActors.Value) { SocialUser user = new SocialUser(); user.AccountName = socialActor.AccountName; user.Name = socialActor.Name; user.ImageUrl = socialActor.ImageUri; users.Add(user); } } //Filter the users return FilterFollowed(users, filter); }