Blog Not just another WordPress weblog


Update Facebook test user password – making batch request with python

A few weeks ago I wrote a post about how to make a batch API call to Facebook to generate MySQL statements. I am going to do a simple Python script to make a batch call to Facebook and update test user's password to "123123"(I just find it easier to type).

Following script really does not check if the batch call being made is over the 50 calls limit, something I will be updating shortly.


Use batch request to grab and save Facebook test user information

Facebook opened up their platform for application developers in 2007 and became one of the most accessed platforms via an API set. Over last few years functional modules were added both to the core API and developers tools offered by the social network giant. One of these amazing developer tool is the test users suite. Other than a few platform limitations and a few reported bugs, it works as expected. The interface for managing test users is not the greatest but it works.

Probably even 2 years ago application developers needed to create a plethora of fake accounts just check usual social sharing and other activities. Facebook deals with fake accounts very strictly now and building and/or testing applications using fake accounts is violation of platform terms.

A Facebook test user can only interact with other test users and application the user is added by the application administrator. A test user can not like a fan page - a lot of the time applications require users to like the fan page it is hosted on. Application developers can bypass the "like gate" for test users by simply matching the incoming user ID with the ones saved in the database as test user.. Also, while building the application, it is better to have data to manipulate. It is a capital mistake to theorize before you have data.

Here is an example using my own jQuery based AJAX call to communicate to Facebook graph API end point, but you can also use Facebook JavaScript SDK is FB.api method. I am using batch API call(or the batch request) to

  1. gather all test users for the application
  2. gather their public information and access token

Initially my script was calling for all test users and after calls the graph API to gather information. The second call was a batch request for all the users. This approach was inefficient for 2 reasosns

  1. making 2 graph API calls
  2. the batch request has a 50 call limit, this approach is useless for an application with more than 50 users. I could however, batch the batch request(will post shortly).

The latest fix for the script did all of it within 1 batch request. I simply specified a dependency  between my requests, my second request is dependent on my first one.

            method                      : "GET",
            name                        : "get-users",
            relative_url                : "/""/accounts/test-users",
            omit_response_on_success    : false
            method        : "GET",
            relative_url  : "?ids={result=get-users:$.data.*.id}"

Specifying omit_response_on_success : false is very important as otherwise the API returns a NULL value for the call. I need the first response as it has the access_token for the users.

Here is the link for the entire script.

I am using Mustache engine to generate and display MySQL statements to the browser window.


Building Facebook application with Kohana 3.0.9

After hearing a lot of good things about Kohana I started to look into it. I did a little history reading and realized it used to be an active fork of CodeIgniter but has changed entirely since version 3, or KO3. At the time of writing this blog, I have spent about 12 hours studying the HMVC framework, so I might be wrong but like always am not in doubt.

As this is my very first encounter with this framework, I decided to follow a series of very helpful tutorials. Currently version is the stable release, but I used the older 3.0.9. I do not see much difference other than how to handle view from the controller. Certainly I have to do more research on this!

Coming from using CodeIgniter for a long time my obvious interest was in the configuration side of things and I am very impressed with Kohana! The configuration was simple and less "variables" to configure.

As I was working with Facebook, my first concern was nice URLs! I had some serious trouble with this and wrote about my experience here. Kohana needed no configuration. Not only that, seems like the SEO friendly URL structure works very nicely with the GET!

Database configuration was ok, nothing special. Maybe it was a little confusing when I had to copy the config files from another location, “database.php” from “modules/database/config/” to “application/config/”.

For PHP syntax errors Kohana is giving me a 324 error and it is a little hard to debug. There might be some ways to enable proper error console.

The naming convention for controllers and models is very interesting, I can't tell if it is any better, but I had no issue so far. Using _ for finding proper location for classes is an old trick but it is done nicely here. Separating the class folder  from the views is a good point.

The before and after methods of the controller is amazing! My approach was using the constructor, but before method provides a good way of initializing my variables. I briefly looked into the template controller which seems to be very efficient. I am not using that controller however.

The most amazing thing about Kohana I think is the ease of  including 3rd party libraries! I created the "vendor/Facebook" folder under the application folder and just dropped the facebook.php file from the Facebook PHP SDK.  Here is the call to include the class

include Kohana::find_file('vendor/Facebook', 'facebook');
$this->facebook = new Facebook(array(
	'appId'  => $this->app_id,
	'secret' => $this->secret,
	'cookie' => true,

This sample application is good as fullwidth (720px) application and a smaller(520px) tab application. The difference is actually not on the CSS, but the way I am handling the permission dialog. From the application, I am redirecting the user to the Graph API authorization page. I could use the JavaScript API but the latter actually fires a browser pop-up window! I am using the JavaScript SDK for permission on the application installed in the tab however. Using this on application installed on a page tab gives a much smoother user experience.

Some interesting Facebook (new)issues I have discovered:

  1. If I am the admin to the page or developer for the application the permission mechanism doesnt work at all sometimes. Even after "liking" the page it is still showing that I have yet to "like" it.
  2. Almost the same thing happens with the permission. When I am the developer I have to keep providing the permission every time I am visiting the app.
  3. If I do not allow the application authorization, it keeps it to that state for a bit and do not let me fire the authorization window again. It does after a few minutes however!

Here is the zip file. The database file(fbkohana.sql) is also included here. I am using jQuery 1.4.4, which is also included in the "assets" folder. Please comment! Find my mistakes and do let me know.

Happy coding!