ChannelStatusUpdate ParseFbStatus(FbStatus fbStatus) { var status = new ChannelStatusUpdate(); status.ChannelStatusKey = fbStatus.StatusId; status.From = fbStatus.From; status.To = fbStatus.To; status.Status = fbStatus.Message; status.DatePosted = fbStatus.DateCreated; foreach (var fbAttachment in fbStatus.Attachments) { var attachment = new ChannelStatusUpdateAttachment(); attachment.MediaType = (short)fbAttachment.MediaType; attachment.PreviewAltText = fbAttachment.PreviewAltText; attachment.PreviewImageUrl = fbAttachment.PreviewImageUrl; attachment.TargetUrl = fbAttachment.TargetUrl; status.Attachments.Add(attachment); } return(status); }
public IEnumerable <FbStatus> GetStatusses(string userid, int pageSize) { Authenticate(); string call_id = GetNextCallNr(); string limit = pageSize.ToString(); Dictionary <string, string> requestParams = new Dictionary <string, string>(); requestParams.Add("method", "stream.get"); requestParams.Add("api_key", apiKey); requestParams.Add("session_key", sessionKey); requestParams.Add("call_id", call_id); requestParams.Add("source_ids", userid); requestParams.Add("v", "1.0"); requestParams.Add("limit", limit); var result = channel.GetStream(apiKey, sessionKey, call_id, GenerateSignature(requestParams, sessionSecret), userid, limit); XNamespace ns = result.GetDefaultNamespace(); foreach (XElement element in result.Descendants(ns + "stream_post")) { var status = new FbStatus(); string id; try { id = element.Element(ns + "actor_id").Value; var userElement = result.Descendants(ns + "profile").First(p => p.Element(ns + "id").Value == id); status.From = new SourceAddress(id, userElement.Element(ns + "name").Value, userElement.Element(ns + "pic_square").Value); if (element.Element(ns + "target_id") != null && !String.IsNullOrEmpty(element.Element(ns + "target_id").Value)) { var toid = element.Element(ns + "target_id").Value; if (!String.IsNullOrEmpty(toid)) { var toUserElement = result.Descendants(ns + "profile").First(p => p.Element(ns + "id").Value == toid); status.To = new SourceAddress(toid, toUserElement.Element(ns + "name").Value, toUserElement.Element(ns + "pic_square").Value); } } status.Uid = Int64.Parse(element.Element(ns + "actor_id").Value); status.StatusId = element.Element(ns + "post_id").Value; status.Message = element.Element(ns + "message").Value; status.DateCreated = Int64.Parse(element.Element(ns + "created_time").Value).ToUnixTime(); } catch (Exception ex) { Logger.Error("Unable to retreive user source address. Result = {0}. Exception = {1}", LogSource.Channel, element.Value, ex); continue; } // If id and actorid are not equal then this is a message directed at user we are // looking at by someone else, in that case skip it as we are only interested in updates // by this specific user. if (userid == id) { yield return(status); } } }
public IEnumerable <FbStatus> GetStatusses(int pageSize) { Authenticate(); string call_id = GetNextCallNr(); string limit = pageSize.ToString(); Dictionary <string, string> requestParams = new Dictionary <string, string>(); requestParams.Add("method", "stream.get"); requestParams.Add("api_key", apiKey); requestParams.Add("session_key", sessionKey); requestParams.Add("call_id", call_id); requestParams.Add("source_ids", ""); requestParams.Add("v", "1.0"); requestParams.Add("limit", limit); var result = channel.GetStream(apiKey, sessionKey, call_id, GenerateSignature(requestParams, sessionSecret), "", limit); XNamespace ns = result.GetDefaultNamespace(); foreach (XElement element in result.Descendants(ns + "stream_post")) { var status = new FbStatus(); try { var id = element.Element(ns + "actor_id").Value; var userElement = result.Descendants(ns + "profile").First(p => p.Element(ns + "id").Value == id); status.From = new SourceAddress(id, userElement.Element(ns + "name").Value, userElement.Element(ns + "pic_square").Value); if (element.Element(ns + "target_id") != null && !String.IsNullOrEmpty(element.Element(ns + "target_id").Value)) { var toid = element.Element(ns + "target_id").Value; if (!String.IsNullOrEmpty(toid)) { var toUserElement = result.Descendants(ns + "profile").First(p => p.Element(ns + "id").Value == toid); status.To = new SourceAddress(toid, toUserElement.Element(ns + "name").Value, toUserElement.Element(ns + "pic_square").Value); } } status.Uid = Int64.Parse(element.Element(ns + "actor_id").Value); status.StatusId = element.Element(ns + "post_id").Value; status.Message = element.Element(ns + "message").Value; status.DateCreated = Int64.Parse(element.Element(ns + "created_time").Value).ToUnixTime(); foreach (var commentElement in element.Descendants(ns + "comment")) { var comment = new FbStatus(); var commentid = commentElement.Element(ns + "fromid").Value; var commentUserElement = result.Descendants(ns + "profile").First(p => p.Element(ns + "id").Value == commentid); comment.From = new SourceAddress(commentid, commentUserElement.Element(ns + "name").Value, commentUserElement.Element(ns + "pic_square").Value); comment.Uid = Int64.Parse(commentElement.Element(ns + "fromid").Value); comment.StatusId = commentElement.Element(ns + "id").Value; comment.Message = commentElement.Element(ns + "text").Value; comment.DateCreated = Int64.Parse(commentElement.Element(ns + "time").Value).ToUnixTime(); status.Comments.Add(comment); } foreach (var attachmentElement in element.Descendants(ns + "stream_media")) { var attachment = new FbAttachment(); attachment.MediaType = (FbMediaType)Enum.Parse(typeof(FbMediaType), attachmentElement.Element(ns + "type").Value, true); switch (attachment.MediaType) { case FbMediaType.Link: { attachment.TargetUrl = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "href").Value); attachment.PreviewAltText = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "alt").Value); attachment.PreviewImageUrl = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "src").Value); break; } case FbMediaType.Photo: { attachment.TargetUrl = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "href").Value); attachment.PreviewAltText = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "alt").Value); attachment.PreviewImageUrl = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "src").Value); break; } case FbMediaType.Video: { var src = new Uri(attachmentElement.Element(ns + "src").Value); var uriParams = NameValueParser.GetCollection(src.Query, "&"); attachment.TargetUrl = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "video").Element(ns + "display_url").Value); attachment.PreviewAltText = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "alt").Value); attachment.PreviewImageUrl = HttpUtility.UrlDecode(uriParams["url"]); break; } } status.Attachments.Add(attachment); } } catch (Exception ex) { Logger.Error("Unable to retreive user source address. Result = {0}. Exception = {1}", LogSource.Channel, element.Value, ex); continue; } yield return(status); } }
public IEnumerable<FbStatus> GetStatusses(string userid, int pageSize) { Authenticate(); string call_id = GetNextCallNr(); string limit = pageSize.ToString(); Dictionary<string, string> requestParams = new Dictionary<string, string>(); requestParams.Add("method", "stream.get"); requestParams.Add("api_key", apiKey); requestParams.Add("session_key", sessionKey); requestParams.Add("call_id", call_id); requestParams.Add("source_ids", userid); requestParams.Add("v", "1.0"); requestParams.Add("limit", limit); var result = channel.GetStream(apiKey, sessionKey, call_id, GenerateSignature(requestParams, sessionSecret), userid, limit); XNamespace ns = result.GetDefaultNamespace(); foreach (XElement element in result.Descendants(ns + "stream_post")) { var status = new FbStatus(); string id; try { id = element.Element(ns + "actor_id").Value; var userElement = result.Descendants(ns + "profile").First(p => p.Element(ns + "id").Value == id); status.From = new SourceAddress(id, userElement.Element(ns + "name").Value, userElement.Element(ns + "pic_square").Value); if (element.Element(ns + "target_id") != null && !String.IsNullOrEmpty(element.Element(ns + "target_id").Value)) { var toid = element.Element(ns + "target_id").Value; if (!String.IsNullOrEmpty(toid)) { var toUserElement = result.Descendants(ns + "profile").First(p => p.Element(ns + "id").Value == toid); status.To = new SourceAddress(toid, toUserElement.Element(ns + "name").Value, toUserElement.Element(ns + "pic_square").Value); } } status.Uid = Int64.Parse(element.Element(ns + "actor_id").Value); status.StatusId = element.Element(ns + "post_id").Value; status.Message = element.Element(ns + "message").Value; status.DateCreated = Int64.Parse(element.Element(ns + "created_time").Value).ToUnixTime(); } catch (Exception ex) { Logger.Error("Unable to retreive user source address. Result = {0}. Exception = {1}", LogSource.Channel, element.Value, ex); continue; } // If id and actorid are not equal then this is a message directed at user we are // looking at by someone else, in that case skip it as we are only interested in updates // by this specific user. if (userid == id) yield return status; } }
public IEnumerable<FbStatus> GetStatusses(int pageSize) { Authenticate(); string call_id = GetNextCallNr(); string limit = pageSize.ToString(); Dictionary<string, string> requestParams = new Dictionary<string, string>(); requestParams.Add("method", "stream.get"); requestParams.Add("api_key", apiKey); requestParams.Add("session_key", sessionKey); requestParams.Add("call_id", call_id); requestParams.Add("source_ids", ""); requestParams.Add("v", "1.0"); requestParams.Add("limit", limit); var result = channel.GetStream(apiKey, sessionKey, call_id, GenerateSignature(requestParams, sessionSecret), "", limit); XNamespace ns = result.GetDefaultNamespace(); foreach (XElement element in result.Descendants(ns + "stream_post")) { var status = new FbStatus(); try { var id = element.Element(ns + "actor_id").Value; var userElement = result.Descendants(ns + "profile").First(p => p.Element(ns + "id").Value == id); status.From = new SourceAddress(id, userElement.Element(ns + "name").Value, userElement.Element(ns + "pic_square").Value); if (element.Element(ns + "target_id") != null && !String.IsNullOrEmpty(element.Element(ns + "target_id").Value)) { var toid = element.Element(ns + "target_id").Value; if (!String.IsNullOrEmpty(toid)) { var toUserElement = result.Descendants(ns + "profile").First(p => p.Element(ns + "id").Value == toid); status.To = new SourceAddress(toid, toUserElement.Element(ns + "name").Value, toUserElement.Element(ns + "pic_square").Value); } } status.Uid = Int64.Parse(element.Element(ns + "actor_id").Value); status.StatusId = element.Element(ns + "post_id").Value; status.Message = element.Element(ns + "message").Value; status.DateCreated = Int64.Parse(element.Element(ns + "created_time").Value).ToUnixTime(); foreach (var commentElement in element.Descendants(ns + "comment")) { var comment = new FbStatus(); var commentid = commentElement.Element(ns + "fromid").Value; var commentUserElement = result.Descendants(ns + "profile").First(p => p.Element(ns + "id").Value == commentid); comment.From = new SourceAddress(commentid, commentUserElement.Element(ns + "name").Value, commentUserElement.Element(ns + "pic_square").Value); comment.Uid = Int64.Parse(commentElement.Element(ns + "fromid").Value); comment.StatusId = commentElement.Element(ns + "id").Value; comment.Message = commentElement.Element(ns + "text").Value; comment.DateCreated = Int64.Parse(commentElement.Element(ns + "time").Value).ToUnixTime(); status.Comments.Add(comment); } foreach (var attachmentElement in element.Descendants(ns + "stream_media")) { var attachment = new FbAttachment(); attachment.MediaType = (FbMediaType)Enum.Parse(typeof(FbMediaType), attachmentElement.Element(ns + "type").Value, true); switch (attachment.MediaType) { case FbMediaType.Link: { attachment.TargetUrl = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "href").Value); attachment.PreviewAltText = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "alt").Value); attachment.PreviewImageUrl = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "src").Value); break; } case FbMediaType.Photo: { attachment.TargetUrl = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "href").Value); attachment.PreviewAltText = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "alt").Value); attachment.PreviewImageUrl = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "src").Value); break; } case FbMediaType.Video: { var src = new Uri(attachmentElement.Element(ns + "src").Value); var uriParams = NameValueParser.GetCollection(src.Query, "&"); attachment.TargetUrl = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "video").Element(ns + "display_url").Value); attachment.PreviewAltText = HttpUtility.HtmlDecode(attachmentElement.Element(ns + "alt").Value); attachment.PreviewImageUrl = HttpUtility.UrlDecode(uriParams["url"]); break; } } status.Attachments.Add(attachment); } } catch (Exception ex) { Logger.Error("Unable to retreive user source address. Result = {0}. Exception = {1}", LogSource.Channel, element.Value, ex); continue; } yield return status; } }
ChannelStatusUpdate ParseFbStatus(FbStatus fbStatus) { var status = new ChannelStatusUpdate(); status.ChannelStatusKey = fbStatus.StatusId; status.From = fbStatus.From; status.To = fbStatus.To; status.Status = fbStatus.Message; status.DatePosted = fbStatus.DateCreated; foreach (var fbAttachment in fbStatus.Attachments) { var attachment = new ChannelStatusUpdateAttachment(); attachment.MediaType = (short)fbAttachment.MediaType; attachment.PreviewAltText = fbAttachment.PreviewAltText; attachment.PreviewImageUrl = fbAttachment.PreviewImageUrl; attachment.TargetUrl = fbAttachment.TargetUrl; status.Attachments.Add(attachment); } return status; }