/// <summary> /// Gets a status message (tweet) from the specified <var>JsonObject</var>. /// </summary> /// <param name="obj">The instance of <var>JsonObject</var> to parse.</param> public static TwitterStatusMessage Parse(JsonObject obj) { // Error checking if (obj == null) return null; if (obj.HasValue("error")) throw TwitterException.Parse(obj.GetArray("error")); TwitterStatusMessage msg = new TwitterStatusMessage { JsonObject = obj, Id = obj.GetLong("id"), IdStr = obj.GetString("id_str"), Text = obj.GetString("text"), Source = obj.GetString("source"), IsTruncated = obj.GetBoolean("truncated") }; // Twitter has some strange date formats msg.CreatedAt = TwitterUtils.ParseDateTimeUtc(obj.GetString("created_at")); // Parse the reply information if (obj.HasValue("in_reply_to_status_id")) { msg.InReplyTo = new TwitterReplyTo { StatusId = obj.GetLong("in_reply_to_status_id"), StatusIdStr = obj.GetString("in_reply_to_status_id_str"), UserId = obj.GetLong("in_reply_to_user_id"), UserIdStr = obj.GetString("in_reply_to_user_id_str"), ScreenName = obj.GetString("in_reply_to_screen_name") }; } msg.Retweets = obj.GetInt("retweet_count"); // Related to the authenticating user msg.Favorited = obj.GetBoolean("favorited"); msg.Retweeted = obj.GetBoolean("retweeted"); // Parse the entities (if any) msg.Entities = TwitterStatusMessageEntities.Parse(obj.GetObject("entities")); // For some weird reason Twitter flips the coordinates by writing longitude before latitude // See: https://dev.twitter.com/docs/platform-objects/tweets#obj-coordinates) msg.Coordinates = TwitterCoordinates.Parse(obj.GetObject("coordinates")); // See: https://dev.twitter.com/docs/platform-objects/tweets#obj-contributors /*if (tweet.contributors != null) { List<TwitterContributor> contributors = new List<TwitterContributor>(); foreach (dynamic contributor in tweet.contributors) { contributors.Add(new TwitterContributor { UserId = contributor.id, ScreenName = contributor.screen_name }); } msg.Contributors = contributors.ToArray(); }*/ msg.User = obj.GetObject("user", TwitterUser.Parse); msg.Place = obj.GetObject("place", TwitterPlace.Parse); return msg; }