Home   RSS Feed

half serious, half half-serious

Content


Facebook’s “Hello World”

Filed under Facebook, Facebook Development, PHP

Hello World. Tearing my fucking hair out here, in my first attempt at developing a Facebook application.

I thought it might be interesting (to some, at least) if I kept track of my progress here. Never know, somebody coming in through Google might find it useful.

I’ve been a hobbyist coder, off-and-on, since I wrote my first

10: PRINT “HELLO WORLD”
20: GOTO 10

when I was eight.

Nowadays I’m no stranger to HTML, PHP, MySQL, so I figured at least setting up Facebook’s sample application, the 2008 equivalent of HELLO WORLD, would be a walk in the park.

Not so.

I’ve only been at it a few hours, merely picking through the step-by-step instructions and I’ve already run into apparent brick walls that had me yelling at my monitor.

Facebook requires developers to place a Client Library, basically a bunch of PHP files containing standard Facebook functions, on their web servers.

Easily done.

Then, you need to create an index.php file – your new application’s main script.

Facebook helpfully provides a very small sample app. All it does, or is supposed to do if I could get the motherfucker to work, is output the id numbers of 25 friends.

I copied the sample code into a fresh index.php file, uploaded it, then tested it on what they call the “Canvas” URL, the front page of your app on Facebook.com.

This page calls your index.php file from your server, runs it and displays the output.

Didn’t work.

I had a hunch what the problem was, but I Googled the error message before making any changes. After trawling through Facebook’s developer forums for half an hour, I was confident enough that I knew what was wrong.

Facebook’s PHP libraries are all in PHP version 5. My web server, at Go Daddy, runs PHP 5 and PHP 4 side-by-side, and requires you to suffix your PHP 5 scripts with .php5, rather than the more usual .php.

Huge pain in the arse, but that’s on Go Daddy, not Facebook.

Because Facebook’s libraries are all suffixed .php, I had to do a little bit of renaming on my server, and in the scripts themselves, to get them to work.



Bingo. The canvas page now at least shows the desired output.

Plus, another two glaring error messages.

Facebook’s REST library is trying to “include_once” a file called “jsonwrapper.php”.

The only problem is that the file doesn’t exist. Either does the jsonwrapper folder.

It didn’t come with the Client Library download, and didn’t show up no matter how many times I re-download and re-unpacked the archive.

So I’d hit my first brick wall. One of the Facebook-supplied libraries is calling another that doesn’t exist, so the sample application is puking up error messages all over the shop.

A search revealed that nobody else on the developer forums appeared to be having the same trouble, so I thought I’d register for the forum and ask.

But I couldn’t, because any attempt to submit the registration form produced “Could not open socket” and nothing else.

So I turned to the Facebook developers’ wiki and searched for “jsonwrapper.php”.

I was momentarily hopeful when I read that: “If you want to use the PHP client library provided you must be using PHP 5.2.X+ as you will get a JSON error if you are running lower than PHP 5.2.”

Warning: include_once(jsonwrapper/jsonwrapper.php) [function.include-once]: failed to open stream: No such file or directory in…

That’s my error message! And it’s saying something about PHP versions! Hurrah!

However: a) my server definitely is running PHP 5.2 and b) I’m pretty certain the PHP command “include_once” always refers to a file, a file which in this case doesn’t exist because Facebook didn’t give me it.

At this point, what’s on my mind is rather GOODBYE WORLD.

After downloading and unpacking the client libraries package half a dozen times with three different compression packages and still not finding the damn file, I was about to throw my keyboard and/or myself out the window, when I found this helpful article at SelfDebugging.com that, almost as a throwaway comment, told me that you don’t even need jsonwrapper.php if you’re running PHP 5.2.

It’s there for backwards compatibility with earlier versions of PHP, apparently.

Since I am running PHP 5.2, I merely deleted the offending “include_once” line in the REST client library, and now the sample app works fine.

What irks me is that Facebook has no way of knowing what version of PHP I’m running when it provided a download of libraries that internally reference a file that it for some reason chose not to supply.

Is this just sloppiness, or is it some kind of deliberate intelligence/persistence test to filter out hobbyists with less time on their hands than I currently do.

Or am I just monumentally dumb?



You Might Like These Posts (automatically generated):

  1. Tarting Up The Facebook Sample App With FBML

2008-11-12  ::  Kevin Murphy

Comments

  1. Nathan
    13 November 2008 @ 6:14 am

    Thanks for this post, it was very helpful (although the cussing wasn’t required)

  2. Phantom
    14 November 2008 @ 2:24 am

    Worked like a charm and I enjoyed the cussing! My feelings exactly!

  3. Cazpa
    14 November 2008 @ 11:13 pm

    Great post, I am in the sample position and found the same problems, deleting the line worked perfect, thanks for posting

    Caz

  4. Moshe Marciano
    22 November 2008 @ 4:49 pm

    Thanks,

    that probably saved me a good few hours….

    Moshe

    http://www.moshemarciano.com

  5. Stephen
    9 December 2008 @ 10:58 am

    Congratulations! You’re top of google for “facebook jsonwrappers.php”.

    I got the warning too, and it seemed to not cause any problems. Nevertheless, I’ve deleted “requires_once(“jsonwrappers.php”)” and it’s working fine, and no warning msg.

    Been Facebook programming for a year now, and I’ve found it to more than 50% painful, just like in your blog.

    Thansk for the blog!

  6. Tal
    21 April 2009 @ 8:43 pm

    THANK YOU SO MUCH !!!!
    you just saved me hours of work :)

  7. Trey Carroll
    7 June 2009 @ 8:49 pm

    I wish others would follow your example and post such hard-won answers. This is saved me from further hours of frustration. I had my code working within 5 minutes of finding this – something that I was unable to solve in 4 hours previously.

  8. Ben Matterson
    3 July 2009 @ 9:34 am

    Awsome, you got my massive map facebook application back up again on the new api version, thanks!

    All praise to the “hobbyist coder”!

  9. Ben Matterson
    3 July 2009 @ 9:37 am

    http://apps.facebook.com/massivemap/

  10. dan
    7 October 2009 @ 3:22 am

    If only i had found this post ealier. Yes it must be a persistence test.

  11. slwf
    28 October 2009 @ 6:17 pm

    Thank you! Exactly what I needed. Both the json error as well as the php5 file extension edit were tripping me up.

  12. Bob
    25 November 2009 @ 4:05 am

    Great post, solved my problem. cussing was spot on and reflected my feeling exatly and gave me a great laugh.

  13. Jim
    3 January 2010 @ 7:41 am

    Awesome, thanks for this post! I’m just getting started, but seeing that this problem wasn’t my error is such a relief.

  14. J.R.
    5 January 2010 @ 3:39 am

    When the libraries were originally published, they must not have included jsonwrapper/ as noted above. These days though, the json files are definitely there in /facebook-platform/php/jsonwrapper folder in the tar file after unzipping. The problem though, is that FB still instructs people to:

    cp facebook-platform/php/facebook*.php MY_DIR

    But, you should also do this:

    cp -r facebook-platform/php/jsonwrapper MY_DIR

    Then, you get all the required code and you don’t have to make the hack noted above (commenting out the “offending” line).

    I guess, these days, there is more than one way to skin this mother fucking cat.

  15. Tarting Up The Facebook Sample App With FBML | texturbation
    14 February 2010 @ 6:07 pm

    [...] yesterday’s headache, getting Facebook talking to my server without throwing up error messages, today I decided to get [...]

  16. John
    5 March 2010 @ 5:45 am

    Kickass dude. Saved me hours of unecessary frustration!

  17. Yongduo
    14 April 2010 @ 7:15 am

    great! Thanks a lot!

  18. Paul
    3 July 2010 @ 7:07 pm

    Wow, thanks. I’ve had warnings for this for so long in my error logs! Never would’ve thought I could just delete that line haha. Thanks!

Add A Comment







Tags you can use (optional):
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>