Example of facebook app which uses offline access permission
Important notice! There was change in API in May 1, 2012. "offline_access" permission was deprecated. Quote: "For existing apps, there are no changes required for your app, but you should consider using the new endpoint". I have to re-write or add fallow up articles to my posts about "offline_access" permission about that suggestion/change. I also have to modify my example and live apps. But AFAIK - there is no hurry, because nothing gets broken that day. Read more about it here
I decided to refresh my knowledge of developing facebook apps. API and PHP SDK has been changed somewhat since my last time I used it. Had to update my previous posts also. I decided to create simple app that collects users access tokens (with offline_access) into mysql database and later uses these to post on their walls. I chose it because lot of people were asking me about this and I need it too soon. I will not explain lot- just download the package and read comments in code. Should be straight-forward and easy to fallow.
Check it out
This app is published at moment. Feel free to check it out or download the source code and start playing. It is also aivable at github. In my working example I use cron to fire "poster.php". There is no self-timer what people have asking about.
Files in package
In this exsample I use only 3 files. config.php, poster.php and index.php.
config.php Needs no comments. Just Fill in. Variables there should be pretty self explanatory.
index.php This collects the access tokens provided by the users. It displays authorising link. After user accepts to give permissions it saves access token into database. For simpler start I included table creation into script- so it will be created automatically (if your mysql user has CREATE permissions).
poster.php This is where real action takes place. It has simple form with some fields. This fields make up post that will be sent on each user's wall after submitting. Afcourse there should be more things covered like token check to remove old and not working ones. But I let you to handle these yourself to keep main code clean.
Set it up
In this post you can read about setting up your iframe application in facebook. It should be fairly simple. You also need to download latest 'facebook.php' (php-sdk) from github and place it next to index.php. Now you should be ready to go.