Useful tips for a Facebook developer
2 min read

Useful tips for a Facebook developer

Before converting to Objective-C and HTML5, I also did some work as a Facebook developer. During that time, I spent a couple of weeks browsing trough their documentation, trying out examples and demos and, most importantly, writing down some useful observations for myself. They concern mostly PHP developers and those working with HTML/Javascript. At that time, I did not look into its mobile sdk API.

Even though at the moment I'm not really working with Facebook's API any longer, I did gather some experience and I'd like to share some of my observations with others.

Useful Observations for Facebook Developers

  • passing data via POST needs the signed_request param included as a hidden field;

  • facebook requests can be sent via a composed link too (the link can be copied from any request page and modified);

  • you can use facebook->api to send data or your own methods;

  • the post id generated contains the user id first. Must be broken in half or the underscore replaced with "posts";

  • JSON data can be converted into arrays for easier handling if you don't have experience working with it;

  • you cannot send identical messages more than one time via the Graph API;

  • to upload an image, you must use $facebook->setFileUploadSupport and upload the image via iframe or popup. Uploading with a multipart form isn’t possible;

  • images can be posted via realpath. This has the following implications: you can only post images from your PC so in order to upload a photo from a link you must use file_get_contents on the image, then* file_put_contents* and then realpath with the recently written image;

  • in order to post with an app on a page as the page admin and not you, you need to have the manage_pages permission, go to USER_ID/accounts on the Graph API, retrieve the access_token for the page in cause and use that access_token to post on the page’s wall;

  • in order to make actions on behalf of the user while he is not online, you need the offline_access permission. Then, you use the $facebook->getAccessToken(); to retrieve the token, store it somewhere (file, database, maybe a cookie). If you want to use that token to automatically “login” without user action, retrieve the token and use it with $facebook->setAccessToken (retrieved_token) to set it. After that, you can make Graph API calls;

  • creating access token can be done at the following link: https://developers.facebook.com/docs/authentication/ under 'App Login'

  • you cannot set an user’s profile picture via the graph api but you can do the following thing: upload a picture to their album and then add &makeprofile=1 to that profile’s link to redirect him towards the profile image cropping page;

  • on using FQL, you also need to pass an access_token if the data you want to access requires permission and is not public. It can be added via &access_token=. If &format=json is added, data will be returned as a json object but it might not be opened within a browser. The default format seems to be XML;

  • to use FQL directly within php, use* $facebook->api(array( 'method' => 'fql.query', 'query' => $fb_query ));*.

The result will be an array, the format parameter being ignored, so we cannot get the result as json or xml;