Archive for the ‘Social Media’ Category

10 links for Facebook developers

Facebook Keegan Street | 25 Aug. 2010 | 5 comments

These are the resources I most frequently refer to while developing Facebook apps. This is by no means an exhaustive list but hopefully it contains something that will help you out.

Official developer’s documentation

Googling for Facebook documentation will often bring you to outdated, incorrect information. Even the official looking wiki.developers.facebook.com contains information that is downright wrong, so stick with developers.facebook.com/docs. Here you can find documentation about everything Facebook: authentication, JavaScript SDK, Graph API, Open Graph protocol, social plugins, FQL, PHP SDK, XFBML and more.

Working examples of Javascript SDK methods and XFBML tags

The best way to learn how these things work is to see some working examples.

Console for testing Graph API queries

If you’re having trouble making Graph API queries from the JavaScript SDK, PHP SDK or some other method, this is a great tool that can help you determine whether the problem is in the query or your other code. It also contains an (almost) exhaustive list of the objects and properties available through the Graph API, but still needs to be updated to include checkins. You can browse through the list and see what information is available to you and the format that it is returned in.

If you see an error message saying "You must use https:// when passing an access token," then change the URL in the input text field from http to https. That’s a bug Apigee needs to fix in its console.

Console for testing FQL queries

FQL queries tend to be more complex than Open Graph queries, so it can be even more valuable to test them out in a console before trying to call them programatically.

URL Linter

If you want your web pages to be shared through Facebook, you will either add Open Graph protocol meta tags or basic meta tags to your pages. No matter which technique you use, the URL Linter can easily show you how Facebook will interpret this metadata when users share your pages.

Developers’ Forum

Draw from the knowledge and experience of over one hundred thousand Facebook developers. Just go easy on the Facebook reps – you can’t expect them to respond to every message or fix every bug. Unfortunately a lot of people tend to be quite disrespectful in the forums.

Bugzilla

The constant innovation of the Facebook platform comes with a price: there is a never-ending backlog of bugs. If you’re banging your head up against the wall because your app isn’t working, more often than not it will be a problem with Facebook’s code rather than yours. Search Bugzilla to find out if other developers are experiencing the same issues as you – and see if or when Facebook plan to fix it.

ThinkDiff.net tutorials

The blog of Md. Mahmud Ahsan contains some really useful tutorials for Facebook development – from getting started with the JavaScript SDK through to advanced topics like using the new iPhone SDK.

Facebook GUI PSD kit

A free set of vector images of Facebook GUI elements like the multi-friend selector and authentication dialogue. Really useful for wireframing and design. Thanks to SurgeWorks for providing this resource.

Publishing Facebook stories on browsers with popup blockers

Facebook Keegan Street | 11 Aug. 2010 | 2 comments

How to use Facebook’s Stream.Publish method on browsers with popup blockers. See a demo.

What is the problem?

Recently many Facebook developers have been frustrated by popup blockers preventing the Stream Publish dialogue box from being displayed. If a user hasn’t logged in and authorised the application, dialogue boxes are shown in a popup window instead of an iframe. That’s fine for some visitors, but for those who have a popup blocker enabled, it means that they won’t see the dialogue box and therefore can’t publish a post into the stream.

The Stream Publish dialogue being displayed in an iframe.
The Stream Publish dialogue being displayed in an iframe.

The Stream Publish dialogue being displayed in a popup window. Popup blockers will prevent this from opening.
The Stream Publish dialogue being displayed in a popup window. Popup blockers will prevent this from opening.

What causes it?

Previously popup blockers didn’t cause any problems for the Stream Publish method because all dialogue boxes were displayed with an iframe rather than a popup window. But in mid-May Facebook discovered that this exposed users to a clickjacking security vulnerability. To address the security problem, dialogue boxes are now shown in a popup window instead of an iframe for users who are not logged in or haven’t authorised the application making the request. According to Facebook, this change is here to stay.

Technically, popup blockers shouldn’t block popup windows that are opened intentionally by the user, for example by clicking on a link that says "Publish this to your profile". Unfortunately however, Facebook have implemented their Stream Publish method in such a way that the relationship between the user action and the popup window being opened is not direct enough. The onus is on Facebook to fix this, but in the meantime, there is a workaround.

The workaround

While not documented by Facebook, it is very easy to construct a URL for the Stream Publish dialogue box. To publish the news feed story, the user simply has to click a link pointing to this URL. Here’s one I prepared earlier. You can construct the URL with your programming language of choice, but I will demonstrate how it works with an ActionScript 3 example. (I have also provided a PHP example in the source download).

1. Defining the post parameters

First we define the parameters for the post, such as the title, link, caption and any media that we want to attach. The attachment and action_links objects follow exactly the same structure as the JSON objects used by the streamPublish method in the JavaScript SDK and the old REST API.

// An event handler which publishes a Facebook story when a button is clicked
private function clickPost(event : MouseEvent) : void {
    // Define the stream story parameters
    var attachment:Object = {
        'name' : "I've just played golf with Lexus at St Andrews.",
        'href' : 'http://apps.facebook.com/myapp',
        'caption' : "Win 2 x VIP tickets to the Open Golf Championships at St Andrews. Simply find the missing golf ball to win - it's quick and fun! Play now...",
        'media' : [ {'type' : 'image', 'src' : 'http://www.myapp.com/assets/share_image.jpg', 'href' : 'http://apps.facebook.com/myapp'}]
    };
    var action_links:Object = [
        {'text' : 'Find the Golf Ball', 'href' : 'http://apps.facebook.com/myapp'}
    ];
    var publishURL:URLRequest = StreamPublish.publishStoryLink('YOUR_API_KEY', attachment, action_links, TopGoals.APP_TAB_URL);
    // Open the URL and Facebook's dialogue box will be displayed
    navigateToURL(publishURL, "_blank");
}

2. Generating the URL

This static method takes the parameters we defined in the previous step and encodes them into a URL. It uses the JSON class from Mike Chambers’ as3corelib project.

package com.thesedays.facebook {
    import flash.net.URLRequest;
    import com.adobe.serialization.json.JSON;

    public class StreamPublish {
        
        /**
         * Generate a URL for displaying the Stream Publish dialogue.
         *
         * @param api_key The API key of your application - you must create an application to call this method.
         * @param attachment An object containing the post text, links, media, etc.
         * @param action_links An object containing actions links of text and hyperlinks.
         * @param next The URL to open after the user has published the post or cancelled it.
         * @param locale The locale code to display the Facebook interface with, for example en_US, fr_FR or nl_NL. It is generally best to leave this parameter as null because then Facebook will determine the language based on the user's browser and session.
         */
        public static function publishStoryLink(api_key:String, attachment:Object, action_links:Object, next:String, locale:String = null) : URLRequest {
            var url:String = 'http://www.facebook.com/connect/uiserver.php' +
            (locale ? '?locale=' + locale + '&' : '?') +
            'api_key=' + api_key +
            '&method=stream.publish' +
            '&channel=' + escape('http://www.facebook.com/xd_receiver_v0.4.php') +
            '&extern=1' +
            '&attachment=' + escape(JSON.encode(attachment)) +
            '&action_links=' + escape(JSON.encode(action_links)) +
            '&display=popup' +
            '&next=' + escape(next);
            return new URLRequest(url);
        }
    }
}

Download the source from this example.

Logging in – a barrier to application uptake?

An analysis of the Facebook “Request for Permission” dialogue as a barrier to application uptake.

I have always wondered how much of a barrier the “Request for Permission” dialogue presents to uptake of Facebook applications. So two months ago I set up a simple one-page app to gather some statistics about user behavior.

My sample group consisted of 4000 unique visitors who spoke English, Dutch, Spanish or Portugese. Visitors came from 82 countries but the largest groups were from Portugal, Belgium, the Netherlands and Argentina.

The idea of the application was very simple. Users were asked to enter their birthday with one of two input methods, either (a) through a series of dropdown boxes or (b) with a button that gave the app access to the birthday on their Facebook profile. The app then calculated how many days, weeks and months the person had been alive for and allowed them to post the result to their Facebook profile.

This is what the input screen looked like:
Your Age in Days input screen

And the resulting profile story:

Your Age in Days result

So what were the results? For whatever reason, 96% of users chose method a – the dropdown boxes. That’s a pretty significant majority, but it doesn’t tell us why users chose this option. They probably had different reasons, but I think some would have been:

  • “The dropdown boxes look quicker and/or easier”
  • “I don’t want to give this application access to my personal information”
  • “I don’t know what will happen if I click the Facebook button”

Personally, I can understand people not wanting to grant the application permission to access their information. Even the lowest level of authorization gives an app access to the user’s name, profile picture, list of friends and other “public” parts of their profile.

Facebook permissions dialogue

Much of the time when we develop Facebook apps we can’t avoid asking users for authorization. But we need to be aware of the barrier this creates. We should delay the authorization request in our application flow until the point where we really need it. And hopefully by that time the user will be able to see the value of authorizing our app.