bakedproject.com Blog Not just another WordPress weblog

16Jun/120

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.

9May/120

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.

1
2
3
4
5
6
7
8
9
10
11
        args.batch.push({
            method                      : "GET",
            name                        : "get-users",
            relative_url                : "/"+app.id+"/accounts/test-users",
            omit_response_on_success    : false
        });
 
        args.batch.push({
            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.