If you want a small program that you can run periodically to backup your blogger blogs, you can use the following source code with the Google GData .NET Library.
See Sorting photo data from Google's Picasa API for another example of using the GData .NET library.
Code highlights
- You need to supply your email address and password at service.Credentials
- You need to specify the backup folder (Dim folder as String =)
- The file is written as an XML file in
- a sub-folder based on each blog's title
- uses a unique filename based on the date and time
Imports Google.GData.ClientImports System.XmlImports System.Text.RegularExpressionsImports System.NetImports System.IOModule Module1Dim exp As New Regex("[^a-zA-Z0-9]")Dim service As New Service("blogger", "BloggerSampleApp")Sub Main()service.Credentials = New GDataCredentials("<emailaddress>", "<password>")Dim query As New FeedQueryquery.Uri = New Uri("http://www.blogger.com/feeds/default/blogs")TryDim bloggerFeed As AtomFeed = service.Query(query)While bloggerFeed.Entries.Count > 0For Each entry As AtomEntry In bloggerFeed.EntriesexportBlog(entry)NextIf bloggerFeed.NextChunk = Nothing ThenExit WhileEnd Ifquery.Uri = New Uri(bloggerFeed.NextChunk)bloggerFeed = service.Query(query)End WhileCatch ex As ExceptionConsole.WriteLine(ex.ToString)End TryEnd SubSub exportBlog(ByVal blog As AtomEntry)Dim title As String = blog.Title.TextDim folder As String = "M:\WWW\Blogs\" + titleConsole.WriteLine(folder)TryIO.Directory.CreateDirectory(folder)Catch ex As ExceptionEnd TryDim filename As String = folder + "\" + exp.Replace(Now.ToString("s"), "") + ".xml"Console.WriteLine(vbTab + filename)Dim o As New FileStream(filename, FileMode.Create)Dim blogId As String = ""Dim ss() As String = blog.SelfUri.Content.Split("/")For i As Integer = 0 To ss.Count - 1If ss(i).ToLower.Equals("blogs") ThenblogId = ss(i + 1)End IfNextDim url As String = "http://www.blogger.com/feeds/" + blogId + "/archive"Dim str As IO.Stream = service.Query(New Uri(url))Dim b(50000) As ByteWhile TrueDim len As Integer = str.Read(b, 0, 50000)o.Write(b, 0, len)If len < 1 ThenExit WhileEnd IfEnd Whilestr.Close()End SubEnd Module
No comments:
Post a Comment