PHP
This is a lightweight API to create Facebook applications in haXe/PHP I wrote for a personal project.
I posted sources on google code .
I use in this API an extern class based on the facebook PHP-SDK.
Example :
package;
import Facebook;
import php.Lib;
class Sample
{
/*Facebook session /!\ very important*/
public var facebook:Facebook;
public static inline var APPURL = "http://apps.facebook.com/YOUR_APP_NAME/";
public static inline var APPID = "YOUR_APP_ID";
public static inline var SECRET = "YOUR_SECRET_KEY";
/*Enable cookie*/
public static inline var COOKIE = true;
static function main()
{
/*Start a new sample*/
new Sample();
}
public function new()
{
/*Get in a Hash-Table the previous constants*/
var params:Hash<Dynamic> = new Hash();
params.set('appId', APPID);
params.set('secret', SECRET);
params.set('cookie', COOKIE);
/*init a new facebook session
and that's all ... :)*/
facebook = FB.init(params, APPURL);
/*Before to do anything in your app, just check if facebook session is set*/
if(facebook!=null)
{
/*Then do as you want...
or use some of the fiew features I added in the API*/
/*Get the current user profile or also his UID (user ID)*/
var currentUser = FB.getCurrentUser();
var currentUID = FB.getCurrentUID();
/*Display his photo*/
Lib.print("<h3>You :</h3>");
Lib.print("<img src='https://graph.facebook.com/"+currentUID+"/picture'> <br/> "+currentUser.get('name'));
/*Get the profile of a specific user*/
var akiavara = FB.getUser("100000322090295");
Lib.print("<h3>Akiavara :</h3>");
Lib.print("<img src='https://graph.facebook.com/100000322090295/picture'> <br/> "+akiavara.get('name'));
/*Get specific fields about a user*/
var fields = FB.getUserFields("raza.tiana", ["id", "name"]);
Lib.print("<br/><br/>My name is "+fields.get('name'));
}
}
}
Try it :
- First step, create your app on facebook.
- Fill the basic form concerning your app.
- Then click on the "CANVAS" section (on the left) and specify a Canvas Page URL and Canvas Callback URL for your application.
Cool, now let's code our app.
Get the sources on google code
Compile the example "Sample.hx" : open a terminal and write this command >
haxe -main Sample -php ./
A directory named /lib will be created + a php file index.php. Upload them in the directory corresponding to your "canvas callback url" you specified in the previous form.
Test your app now :
http://apps.facebook.com/YOUR_APP_NAME
That's it !
Page(s) :
1
Contact
Follow me