I realized that my last few posts had been heavy on the thinking and light on the code. After working with Sandeep and Jeff on their Dreamforce session, Leveraging Public Social Networks (make sure you sign up for it, it rocks!) I had me a hankering for some development.

In support of Sandeep and Jeff’s session we will be making the new Facebook toolkit available for download. The net result was that I had to finish off the getting started article and tie up a few loose ends. One of these loose ends was write the profile image component. The good news is that the toolkit is designed well and easily supports new objects and extensions so putting the plumbing in place was pretty easy:

1. Write a Component 

Components are a great practice to encapsulate your code, and make developing Visualforce pages a snap:

2. Update the FacebookUser object

3. Update the FacebookObject superclass.

This was where things got a little sticky to start with. Apparently when you make a Facebook Graph API call to  get the image with a URL like graph.facebook.com/717838202/picture it actually does a temporary redirect to another URL (In my case, http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs341.snc4/41369_717838202_1756_q.jpg – I can’t help but wonder if Mark Zuckerberg learnt from his Face Mash site). Thankfully 302’s (the code for a temporary HTTP redirect) store the redirect location in a header, “Location”, as part of the HttpRedirect.  

With a little bit of Apex magic, I was back in business:

The result, thanks to the toolkit, is a very easy way to drop Facebook profile images into your Visualforce page:

Profile

If you are already registered for Dreamforce, make sure you register for the Leveraging Public Social Networks session at Dreamforce and learnhow to get start developing with the Facebook toolkit!

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS