Task <FacebookLikeInfo> GetLikeInfo(string url, CancellationToken token) { var session = EnsureLoggedIn(); var likeRequest = session.Service.CreateRequest("GET", new Uri(BaseUri, "me/og.likes"), session.Account); likeRequest.Parameters ["object"] = url; var likeCountRequest = session.Service.CreateRequest("GET", new Uri(BaseUri, "fql"), session.Account); likeCountRequest.Parameters["q"] = string.Format("SELECT total_count, comments_fbid FROM link_stat WHERE url=\"{0}\"", url); var req = CreateBatchRequest(likeRequest, likeCountRequest); return(req.GetResponseAsync(token).ContinueWith <JToken> (GetResponseJson).ContinueWith(t => { var likeInfo = new FacebookLikeInfo(); var data = (JArray)t.Result; var likeRes = JObject.Parse(data[0].Value <string> ("body")); if (likeRes["error"] != null && likeRes["error"].Value <int> ("code") == 1) { // there is no graph object for the stamp return likeInfo; } var likeCountRes = JObject.Parse(data[1].Value <string> ("body")); var likeCountData = likeCountRes["data"][0]; likeInfo.LikeCount = likeCountData.Value <uint> ("total_count"); likeInfo.ObjectId = likeCountData.Value <string> ("comments_fbid"); // likeData = null: graph object exists, but user didn't like it if (((JArray)likeRes ["data"]).Count > 0) { var likeData = likeRes["data"][0]; likeInfo.LikeId = likeData.Value <string> ("id"); } return likeInfo; })); }
Task<FacebookLikeInfo> GetLikeInfo (string url, CancellationToken token) { var session = EnsureLoggedIn (); var likeRequest = session.Service.CreateRequest ("GET", new Uri (BaseUri, "me/og.likes"), session.Account); likeRequest.Parameters ["object"] = url; var likeCountRequest = session.Service.CreateRequest ("GET", new Uri (BaseUri, "fql"), session.Account); likeCountRequest.Parameters["q"] = string.Format ("SELECT total_count, comments_fbid FROM link_stat WHERE url=\"{0}\"", url); var req = CreateBatchRequest (likeRequest, likeCountRequest); return req.GetResponseAsync (token).ContinueWith<JToken> (GetResponseJson).ContinueWith (t => { var likeInfo = new FacebookLikeInfo (); var data = (JArray) t.Result; var likeRes = JObject.Parse (data[0].Value<string> ("body")); if (likeRes["error"] != null && likeRes["error"].Value<int> ("code") == 1) { // there is no graph object for the stamp return likeInfo; } var likeCountRes = JObject.Parse (data[1].Value<string> ("body")); var likeCountData = likeCountRes["data"][0]; likeInfo.LikeCount = likeCountData.Value<uint> ("total_count"); likeInfo.ObjectId = likeCountData.Value<string> ("comments_fbid"); // likeData = null: graph object exists, but user didn't like it if (((JArray) likeRes ["data"]).Count > 0) { var likeData = likeRes["data"][0]; likeInfo.LikeId = likeData.Value<string> ("id"); } return likeInfo; }); }