Tuesday, 13 July 2010

I use Posterous for publishing photographs online. I like the easy posting by email, the maps for geotagged photos and the integration with Twitter, Facebook, Flickr etc. If, like me, you use ASP.NET for your website, here's a little function to get the lastest photos from your Posterous feed.

Function GetPosterous() As String

    Dim myMediaNameSpace As XNamespace = "http://search.yahoo.com/mrss/"

    Dim myAPI As New XDocument

    myAPI = XDocument.Load("http://[YOUR USERNAME].posterous.com/rss.xml")

    Dim Posts = (From Post In myAPI.Descendants("item") _
            Select PostLink = Post.Elements("link").Value, _
            PostImage = Post.Element(myMediaNameSpace + "content").Element(myMediaNameSpace + "thumbnail").Attribute("url").Value _
            ).Take(2)

    Dim sb As New StringBuilder
    Dim myQuery = From c In Posts

    For Each MyX In myQuery

        sb.Append("<a href=""" & MyX.PostLink & """ ><img src=""" & MyX.PostImage & """ style=""border-width:0px; width:250px;"" /></a><br /><br />")

    Next

    Dim myStr As String = sb.ToString
    Return myStr

End Function

Be sure to import System.Linq, System.Xml.Linq, add some caching and you're done.



Share this webpage Comments on this webpage