Home RSS feed

 

Facebook book

This is how I made a facebook book.

Physical facebook book

First we need to get the data. We don't have to write an app, we just need an access token and a url. This can be obtained e.g. by browsing to Facebook's developer resources. After logging in you can find the following link:

https://graph.facebook.com/me/photos?access_token=xxx

"/me" could be substituted with a friend's username or profile id. Append "&limit=999" to get more at once. The data is returned in json:

{
   "data": [
      {
         "id": "10101470046392053",
         "from": {
            "name": "Richard H. Tingstad",
            "id": "1245408"
         },
         "picture": "https://fbcdn-photos-a.akamaihd.net/xxx_s.jpg",
         "source": "https://fbcdn-sphotos-a-a.akamaihd.net/xxx_n.jpg",
         "height": 540,
         "width": 720,
         "images": [
            {
               "height": 1536,
               "width": 2048,
               "source": "https://fbcdn-sphotos-a-a.akamaihd.net/xxx_n.jpg"
            }, ...

To turn this into a printable book I chose to use XSL-FO. This means that the data first has to be converted into xml. We get something like:

<data>
	<id>10101470046392053</id>
	<from>
		<name>Richard H. Tingstad</name>
		<id>1245408</id>
	</from>
	<picture>https://fbcdn-photos-a.akamaihd.net/xxx_s.jpg</picture>
	<source>https://fbcdn-sphotos-a-a.akamaihd.net/xxx_n.jpg</source>
	<height>540</height>
	<width>720</width>
	<images>
		<height>1536</height>
		<width>2048</width>
		<source>https://fbcdn-sphotos-a-a.akamaihd.net/xxx_n.jpg</source>
	</images>
	<images>
		<height>540</height>
		<width>720</width>
		<source>https://fbcdn-sphotos-a-a.akamaihd.net/xxx_n.jpg</source>
	</images> ...

There are many root "data" elements, so I added an all-surrounding "foo" tag. Next, I wanted to download the image files. Every photo has several sizes. To get the largest ones, I used the following xslt:

<xsl:for-each select="images">
	<xsl:variable name="w" select="number(width/text())"/>
	<xsl:if test="not(../images[width &gt; $w])">
		<xsl:value-of select="source"/>
		<xsl:text>
</xsl:text><!-- newline -->
	</xsl:if>
</xsl:for-each>

The XPath expression "/foo/data/images[1]" would probably work too, as they appear to be in the correct order. I piped the results to a text file, then downloaded them:

cat images.txt | while read a;do wget $a;done

Ironically, while I want high quality images now, I usually upload low resolution files myself. It's one of the jobs of my photo script (which has been heavily updated recently). Therefore, I manually replaced some of my pictures with high resolution files. The major step in the book exercise is the XSL transform. Feel free to download and use this file. Apache FOP can use this file to generate a PDF file.

To print the book, I ordered a photo album and uploaded each page as a jpg file:

convert -density 300 file.pdf files.jpg

Next time, I'll consider including QR codes in my book too, linking to the photos on facebook.com.

Tags: xslt, facebook, xsl-fo, pdf, photo

Created on Wed, 05 Sep 2012 19:00

blog comments powered by Disqus