Build 10 classic Flash games and learn game development along the way with this ultra-fast paced game development course.

If you love this blog, this is the book for you.

Buy the book

Get the source code of 12 commercial Flash games, which have been loaded more than 50 million times!

Learn from real world successful examples.

Get it now

Box2D for Flash Games teaches you how to make Flash physics games from scratch with the most advanced features.

Create the new Flash game smashing hit.

Buy the book

PHP Facebook Graph API “Hello World” application

While I am preparing a new tutorial about Facebook applications (and a php FB game, maybe HTML5 based), I notice there isn’t any “Hello World” application about Facebook applications using the new Graph API with just some PHP lines.

If you don’t know what is the Graph API and don’t want to get an headache with strange words such as “access token”, ever mind… as said I’ll explain it in a few days. But if you are already messing with Graph API and Facebook and are looking for a really simple and working code, this is the post for you.

Try the application: Hello World.

… and get the source code:

… and don’t try to steal my secret key, it’s not real…

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (13 votes, average: 4.54 out of 5)
Loading ... Loading ...
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 13 comments

  1. Tony Lukasavage

    on September 19, 2010 at 2:31 am

    I get an error when I click your HelloWorld link:

    Current session content:
    NULL
    Facebook exception: OAuthException: An active access token must be used to query information about the current user.

  2. Gagandeep Singh

    on September 19, 2010 at 7:33 pm

    That is how it is implemented. click on get access token and give this app required permissions. Then you will not get this error.

  3. Dmillos

    on September 21, 2010 at 8:52 am

    Hi Emanuele, once again, thank you very much for your help, I just had a quick question for you, I tried looking online but I couldn’t really find an answer, so hopefully you can help.

    I am currently developing a game to put on facebook and I was wondering what is the best way to communicate with it, so far I found 3 possibilities: using Adobe’s Facebook – Flash API, using facebook.php file or using the Graph API released by facebook some time ago.

    My first thought is that the last one is the latest, therefore must be the most useful, althou I am not sure If how to get the data from flash.

    Thanks a lot for your help and your awesome Tutorials. you are the best!!

    -Daniel

  4. superman

    on September 24, 2010 at 10:55 pm

    hey mate, thanks for the tutorial. it helped alot, but can telme, how to get, users extended permissions on Graph Api, plus, how does the Publish functions works and etc etc?
    need a tutorial for that too please :)

  5. Christian Scholz-Flöter

    on October 1, 2010 at 12:42 pm

    Do you mean Emanuele’s example script just works that way or do you mean Facebook made it so that users will get error messages like the one mentioned by Tony when they are working with the new Graph API?

    Because, naturally, I wouldn’t want my users to have to endure seeing a cryptic error message and then having to do another click.

    My question — someone here hopefully can answer since the Facebook documentation is wasted webspace — is:
    How would the script look like with the get active access token part automated?

    Thanks for sharing, everyone!

  6. Mukesh

    on October 15, 2010 at 4:11 pm

    Hi,
    Did u find a way to get active access token part automated??
    Thanks

  7. Lana Michelle

    on October 18, 2010 at 6:31 am

    Hi there, Sorry if this is not in the right place but I honestly couldn’t figure out where to send you a message. First off thank you very much for the game Glomb (on Facebook)… it has provided me with hours of entertainment trying to beat my nieces score :o) Unfortunately, it does not seem to want to record scores. In all the games I have played it has recorded only one and, of course, it was a terrible score. Please help restore my dignity and fix the score keeping lol Thank you very much! :o)

  8. Udar

    on October 22, 2010 at 11:15 am

    did you publish already follow up of this article as advised in begining ? I tried to find it but no succes!

    Great job…it is really confusing after switching to new api! Thanks

  9. gus

    on May 21, 2011 at 12:27 am

    http://apps.facebook.com/hello_worldz/

    Current session content:

    NULL

    Facebook exception: OAuthException: An active access token must be used to query information about the current user.
    Get access token

  10. Jack

    on June 11, 2011 at 1:00 pm

    facebook api is hard to use for me.

  11. Wyand

    on June 24, 2011 at 9:30 am

    I get Fatal error: Call to undefined method Facebook::getSession(). Which library are you using?

  12. Eshriek

    on August 9, 2011 at 4:04 am

    I’m using php sdk v. 3.0.0 If you are too try replacing getSession() with getUser()

  13. WebMasterOne

    on November 29, 2012 at 3:52 pm

    Ciao Emanuele
    a little question 4 u, as i can’t find into internet a complete exmple on wath i would like to have.
    All the example, infact, are for website pages, where the user can do the Facebook Login.
    I’ve a differrent situatuation.
    At the moment i’ve a conjob that twice an hour download all the quakes accourred in italy.
    And at the moment i’ve a cronjob (php script) that publish this events on my group page using the old api
    infact i use:
    $url_facebook = “https://api.facebook.com/method/stream.publish?message=”.$messaggio.”&attachment={\”name\”:\”".$titolo.”\”,\”href\”:\”".$action_link.”\”,\”caption\”:\”".$caption.”\”,\”description\”:\”".$testo.”\”,\”media\”:[{\"type\":\"image\",\"src\":\"".$image."\",\"href\":\"".$action_link."\"}]}&action_links=[{\"text\":\"".$link_name."\",\"href\":\"".$action_link."\"}]&target_id=”.$target_uid.”&uid=”.$source_uid.”&”.$site_token.”";
    simplexml_load_file(“”.$url_facebook.”");

    I’m looking an example for doing the same thing with the graph api.
    The post are to be published to 3 group, and my profile (4 all the group, i’m the admin)
    I’ve my app with my code and secret, of course…

    I hope you will help me

    thanks

    Mario