Facebook Connect Stream.Get().Post.TimePosted Question

Jul 16, 2010 at 7:28 PM

Hello,

I'm trying to get the time a post was made to the news feed. Below is a small snippet of my code. Any help would be appreciated.

In addition, thank you to ALL the developers that have, and are, taking their time to put this C# wrapper together!

Cheers,

Herb

 

MY CODE (Look for my comments in the code closer to the bottom of the function):

  private string GenNews(stream_data newsfeed, IList<user> friends)
        {
            StringBuilder sb = new StringBuilder();

            long llUser = Api.Users.GetLoggedInUser();
            user loggedInUser = Api.Users.GetInfo(llUser);
            user poster = null; 

            sb.Append("You are currently logged in as " + loggedInUser.name + ".<br />");
            sb.Append("<table>");
            
            foreach (stream_post post in newsfeed.posts.stream_post)
            {
                if (post.actor_id == Convert.ToInt64(connectSession.UserId))
                {
                    poster = loggedInUser;
                }
                else
                {
                    IEnumerator<user> iter = friends.GetEnumerator();
                    while (iter.MoveNext())
                    {
                        if (((user)iter.Current).uid == post.actor_id)
                        {
                            poster = (user)iter.Current;
                            break;
                        }
                    }
                }

                //Build Row & Column
                sb.Append("<tr><td>");
                
                //Build News Wall
                sb.Append("<hr width='100%' />");
                                sb.Append("<a href=\"" + poster.profile_url + "\" target=\"_profile\">");
                sb.Append("<img src=\"" + poster.pic_square + "\" width=\"50\" height=\"50\" alt=\"" + poster.name + "\" />");
                sb.Append(poster.name);
                sb.Append("</a>");
                sb.Append("<br/>" + post.message + "<br />");

                // *******************************************
                // THIS IS WHERE I AM GRABING THE TIME THE POST
                // WAS MADE. IT ONLY DISPLAYS A 'LONG' DATA TYPE
                // WHAT IS THE PROPER CONVERSION TO DISPLAY TIME?
                // *******************************************
                sb.Append("at" + post.updated_time.ToString());

                //Close Column & Row
                sb.Append("</td></tr>");
            }
            
            sb.Append("</table>");
            return sb.ToString();
        }

Jul 17, 2010 at 6:14 PM

Well, if this helps someone then my pains of overlooking the Facebook.Utility Namespace won't be in vain :)

 

Here's the code to display the stream_post.updated_time, as a date:

// Display time post was made
DateTime value = Facebook.Utility.DateHelper.ConvertUnixTimeToDateTime(post.updated_time);
sb.Append("<span style='ADD YOUR STYLE HERE'>");
sb.Append("at : " + value.ToString() + "</span>");

Cheers,

Herb