public static FacebookOAuthResult <FacebookLikes> GetAllUserLikes(string facebookId, string accessToken) { FacebookOAuthResult <FacebookLikes> result = new FacebookOAuthResult <FacebookLikes>(); result.Data = new FacebookLikes(); IStopwatch watch = MonitoringTimers.Current.GetNewStopwatch(true); try { result.Data.Next = facebookId + "/likes?format=json&limit=5000"; do { dynamic d = GraphAPI.Get(result.Data.Next, accessToken); FacebookLikes pageResult = ConvertToFacebookLikes(d); if (pageResult.Likes != null && pageResult.Likes.Count > 0) { result.Data.Likes.AddRange(pageResult.Likes); result.Data.Next = pageResult.Next; if (pageResult.Likes.Count < 5000) { result.Data.Next = null; } } else { result.Data.Next = null; } }while (!string.IsNullOrEmpty(result.Data.Next)); } catch (FacebookOAuthException) { result.SetHasExpired(); } catch (Exception e) { result.HasError = true; Logger.Current.Error("SocialGraph.GetFriendIds", "Could not update a Facebook user's social graph", e); } finally { //TODO : ajouter un compteur sur le nombre de like récupérés watch.Stop(); MonitoringTimers.Current.AddTime(Counters.Facebook_GetUserLikes, watch); } return(result); }
public static FacebookOAuthResult <dynamic> GetUserProfileFieldSync(string facebookId, string fields, string accessToken) { FacebookOAuthResult <dynamic> result = new FacebookOAuthResult <dynamic>(); IStopwatch watch = MonitoringTimers.Current.GetNewStopwatch(true); try { dynamic d = GraphAPI.Get( string.Format("{0}?fields={1}", facebookId, fields), accessToken); result.Data = d; } catch (FacebookOAuthException) { result.SetHasExpired(); } catch (Exception e) { Logger.Current.Error("Profile.GetUserProfileFieldSync", "Could not retrieve Facebook user's profile field", e, fields); } finally { watch.Stop(); var counter = Counters.Facebook_GetUserProfile; if (fields.Contains("likes")) { counter = Counters.Facebook_GetUserLikesAndProfile; } MonitoringTimers.Current.AddTime(counter, watch); } return(result); }