As I have mentioned before, we can call both the Facebook's Graph API and the old REST API by using the PHP SDK.

In this part of the tutorial, we will see why we still need to call the old REST API and how to do it.

 

Why Still Want to Call the old REST API?

It is true that the Graph API is easy to use. It provides a consistent way of reading and writing Facebook's object. As a result of this intent, the Graph API does not provide us with as many high level and feature-rich functions as in the old REST API. For example, in the old REST API, we can get the user IDs of the current user's Facebook friends who have authorized the specific calling application by using the friends.getAppUsers API. However, there is no such a connection object in the Facebook social graph (it is reasonable for this). Though it may be possible to have this done by using the Graph API, one may still prefer to make the old REST API call (as we can write less code and it probably performs better).

Another reason for not using the Graph API is because of its known bugs/limitation. For example, at the time of writing this, although we can publish a post to the user's wall, the "optional app-specified action" is not supported.


How to Call the Old REST API via the PHP SDK?

Just like calling the Graph API, we call the Old REST API by using the api method in the PHP SDK application instance.

 

Getting the User's Friend List via the old REST API

Name Lookup Timed Out Error in Calling the old REST API

As usual, for what I have mentioned in the tutorial, I implement it in the demo app.

To get the user's friend list, I have added the "My friends (Old REST)" tab. After migrating the code, I have encountered the following error:

Facebook dashboard header

By looking at the facebook.php, the error is returned when making the request to Facebook's server.

It is interesting to note that the PHP SDK will make the old REST API call to different Facebook's server based on whether the API call is a "READ_ONLY_CALL" or not. For "READ_ONLY_CALL" requests, they will be passed to "api-read.facebook.com". Otherwise, the request will be passed to "api.facebook.com".

While I have no control on how the name lookup is done on the web server (as I am using web host services), I have tried to amend facebook.php by renaming "api-read.facebook.com" to "api.facebook.com". Well, the name lookup problem is resolved.

Looking at Facebook's bug tracking system reveals the fact that I am not the only one who have encountered this. So, you may want to apply the same "workaround" if you encounter the same problem.

 

You can test drive the above feature in the enhanced "Our 1st FB App (PHP SDK)".