Tutorial: Facebook Friends Leaderboard
I decided to start a simple website (iDeveloper) for the sole purpose of posting tutorials and code on how to do things in Corona that you really can't find anywhere else at the moment.
At first, I simply wanted a place to keep track of how to do some of the more advanced things I figure out so I didn't have to keep looking at the source of my previous projects, but I decided to make it public so everyone can benefit from it.
My first is an in-depth tutorial that shows you how to implement a Facebook Friends Leaderboard that's very similar to what you see in games like Doodle Jump and Bejeweled Blitz. I think it makes games much more competitive and addictive when you can see your score up against your friends.
So without further ado, here's the link to the tutorial:
--> http://ideveloper.kodingen.com/2010/facebook-friends-leaderboard/
Comments are turned off on the blog so please reply to this thread if you have any questions or comments regarding the tutorial!
Replies
Thanks for taking the time to view the tutorial, Mike!
Let me know if you need any help and if/when you put it in any of your games!
Yes, I will do that.
jonbeebe Great site you started there. I like your and your wife's tumblr blogs too. Since I'm on tumblr also I was able to subcribe to your blogs.
Wow! This is great Jonathan, just had a quick read through the tutorial and I'll definitely be implementing this.
I want to give a big thanks to you too for posting the link to your Corona review on Touch Arcade a few weeks ago. It was because of this that I reacquainted myself with Corona after checking it out early on and was able to buy it just before the price rise :)
I'm loving Corona and it has motivated me into action to finally turn my ideas into real games. So thanks again and I look forward to working through your tutorials, you are a great ambassador for Corona!
@tokyodan: Thanks a lot for your compliments, and for following us on tumblr! I hope you enjoy the content on the new site.
@bherron: Please let me know when you implement it in one of your apps! It'll definitely feel good to see it in action elsewhere, to know someone really got some benefit out of it. I literally worked all night long trying to figure out how to do that (wrestling with JSON and the Facebook API was the worst, because I have little experience with both).
I'm also glad to hear that my Corona review had an effect on your decision! I didn't mean to post it right before the price jump, but I guess that worked out well in Ansca's favor :-)
Hi jonbeebe. I am having difficulties on step 2. Facebook setup. I am confused about the site and site URL. I setup a website for my business and a page for the app but it won't accept the URL saying it needs to point to a directory. Any suggestions?
Thanks
great! thanks for sharing
Was wondering if anyone could help. I followed the process step by step but I seem to keep getting "internal server error" messages. I am a complete beginner about php and mysql. I did set up a database through my hosting at godaddy and was able to create a new table as instructed. I have the suspicion that my issue is in the server name.
In the documents it says that it's usually "localhost" but when I click on myphpadmin page for server it actually gives me an ip address. Anyways I tried both and get the same error, which doesn't really give me much room for debugging.
Any help is appreciated and thanks a bunch again to jonbeebe for this tutorial.
Thanks
Hey leo, sorry for the late reply.
Some hosts are a little different when it comes to the server address. Along with the IP address, does it also give you a port?
@jonbeebe, just sent you an email. Thanks for the help.
Hi Jonbeebe,
First of all, thanks for this tutorial, it's very well written and easy to use.
I've created my facebook app, and my database, and I'm now trying to test your different scripts via my web browser. I managed to fill the database with 2 scores, by calling http://www.blabla.com/leaderboard/sendscore/?score=50
But now, when I try to load the following page :
http://www.blabla.com/leaderboard/loadfriendranks/?bestscore=50
My browser connects to facebook.com (ok), and then, I get the following warnings on my page, and my HighScore table is empty :
Warning: file_get_contents(https://graph.facebook.com/oauth/access_token?client_id=0000000000&type=web_server&redirect_uri=http%3A%2F%2Fwww.blabla.com%2Fleaderboard%2Ffriendranks&client_secret=%00000000000&code=0000000000) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /homez.358/--xxxx--/www/leaderboard/friendranks/index.php on line 56
Warning: file_get_contents(https://graph.facebook.com/me?) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /homez.358/--xxxx---/www/leaderboard/friendranks/index.php on line 61
Warning: file_get_contents(https://graph.facebook.com/me/friends?) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /homez.358/--xxxx--/www/leaderboard/friendranks/index.php on line 105
Warning: Invalid argument supplied for foreach() in /homez.358/--xxxx--/www/leaderboard/friendranks/index.php on line 112
Have you got any idea of what I did wrong ?
Thanks by advance,
Antoine
Hey jonbeebe,
I seem to be having the same problem as amigoni - I am receiving an Internal Server Error. I'm pretty sure I have the MySQL db connections correct... Any idea on why I am receiving this error? Thanks for all your hard work on the project!
-David
Hey, beebe! I'm following your tutorial right now trying to implement a highscore list to my game. Great tutorial mate, very easy to follow!
Got 2 questions though.. First, when trying to do this: "In the Web Site sub-panel, make sure your Site URL is set to the online location that your PHP scripts will be located. Ex. http://www.yoursite.com/yourgame2", facebook gives me an error message.
"Validering misslyckades.
Webbplatsens domännamn: http://www.bubblesonly.com/scripts/ is not a valid domain."
which basically means, validation failed. the websites domainname is not a valid domain. What am i doing wrong? I've bought the domain and i got a folder in the ftp called scripts, so that URL is valid?
Second, in friendranks/index.php, where i need to edit the database_server. Do i paste the whole URL of the database_server? I bought my domain from one.com and they provide a myPhpAdmin database with the URL https://dbadmin.one.com/ for log in. Should I paste this whole URL in there?
Thanks!
@nahir: It's been a while since I took a look at this, but the Facebook options might've changed.
It sounds like they want just your domain name, which would be: bubblesonly.com
Also, this script isn't entire secure (it actually can be easily hacked by outsiders to inject false scores), so if you get a chance, you might want to implement some sort of client-server security, or hire someone to do so. This script is bare-bones.
Oh ok, but then why bother write a tutorial you advice people not to follow? :-P
Thanks for the warning!
The tutorial is pretty old, but it still works really well!
I'm just giving a disclaimer, that if you intend to use for a serious game, you need to have some kind of security implemented. The script still takes care of most of the "hard stuff", so its still very useful to many people.
The database server should be in your database admin. Most of the time, it is just localhost.
Alright, thanks a lot :-)
That is a very useful tutorial, but more importantly for me is that kodingden link. I've never heard of them before, very cool.
I found out that fbid column must be of type BIGINT.
thanks a lot for this, still works!
in case someone gets the same problem: I first got a server SSI directive error, but when i deleted the .htaccess file from the friendranks folder it worked!
will use this in my new game!
I have tried to include this facebook friends leaderboard to my game, but i havent succeed. In my game, when web pop up launch, it just says:
Not Found
The requested URL /home1/uapo15/loadfriendranks/ was not found on this server.
My database and php scripts are in heliohost.org
In heliohost.org shows that my main domain is: uapo15.heliohost.org
and home directory is: /home1/uapo15
In php scripts i have putted http://uapo15.heliohost.org/home1/uapo15/ in $scriptTopLevel variable.
Stupid question, but do i need to make some kind of facebook login to my game? Now i have only putted this code to my game:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | local touchHighScoresBtn = function( event ) if event.phase == "release" then local webListener = function( event ) local shouldLoad = true local url = event.url if 1 == string.find( url, "corona:close" ) then -- Close the web popup shouldLoad = false end return shouldLoad end -- show web popup local showRanksUrl = "http://uapo15.heliohost.org/home1/uapo15/loadfriendranks/?bestscore=" .. bestScore native.showWebPopup( showRanksUrl, { urlRequest=webListener } ) end end |
Could someone help me, please??
Thanks Jon, this is a great and helpful initiative. I am wondering if it would be worthwhile for the community to help build a library of pluggable lua files to speed up game development.
Things i can think of
A template with basic director integrated for screen changes
A scoring framework
Optional integration of scoring with openfient or facebook
A customizable in-game score board
A dev time memory and stats checker
A framework for allocating and releasing memory for objects
Would really love to see some integration of these in tools like the corona project manager which IMO can turn into a IDE with built in features which provide a headstart to rapid dev for corona.
What do you think?
Can somebody help me? I really appreciate if someone could help me little bit. Check my problem 2 post above.
Please help me with facebook friends leaderboard. I dont know what i shoud do to get it work.
I feel like I'm late to the party! Jonathan, what a fantastic and generous site to be sure. Kudos for your generosity. I was looking for information about Apple's Leaderboard functionality and how to implement - and stumbled across this thread.
I'm so excited now to digest what's there... I'm curious to see how you did your screen management.
As soon as our main.lua grew to something unmanageable we knew require" " would be our friend and we started immediately breaking up our code into manageable chunks. I'm curious to see how you did it now.
To be continued...
Hi Jon,
I'm going to use your tutorial to code up an interface to Facebook for my new game. Thanks for posting that great info.
I'm not a facebook user myself, so I am looking for some examples of how the user interface was actually done. I see that your Dungeon Tap game's features include all these elements, so I went to buy it, but it is not for sale on the store. How can I get a copy? Can you suggest another game to substitute?
I am getting the error message below...any ideas what the problem could be.
Error inserting new user
Also in the tutorial it says:
"In the Mobile and Devices sub-panel, make sure Application Type is set to HTML 5 / mobile web"
...but I don't see anyplace to set the Application Type...it just asks for app ID info so can you clarify this?
--Thx, Mike
Hi, does this support Single-Sign-On (SSO)? If not does anybody know if it's possible with Corona?
What is the code to disconnect from Facebook?
1 | facebook.logout() |
I am getting this error
Invalid argument supplied for foreach() in /friendranks/index.php on line 112
Anyone still using this?
Does it still work?
I am getting a 500 Internal Server error when I visit the URL, as others have stated. Is this a database config issue? Is there a better solution since this was made?
it was my .htaccess file. deleted it and it works now.
Matt,
Do you have a dedicated server for this (will regular website hosting work)?
What do i need in order to set this up?
Thanks!
Yea regular webhosting with php (pretty much all do) and ability to make a MySQL database (also very common). If you need some help let me know and we can skype or something.
If we could skype that wold be great! please add me: ron.j.barak
i read somewhere about face book using https and requiring an ssl certificate.
this code works well and is a good idea, does any body know if your server needs and ssl certificate for this code?
Hey Matt
I came across Johns tutorial the other day on the ideveloper link... but its not available at the moment. Not sure if its been removed!
It sounds like you got this working before...? You dont have the details to integrate this into an app? I grabbed the php scripts before the tutorial went offline.. but dont have the details for the Corona side of things
If anyone else has the documentation that was online available would you be able to send it my way?
Cheers
Richie
Think it might be a good idea if the Corona bods (ala Brent/Rob) created an updated tutorial on this subject - Facebook Friends seems to be a concept popular enough for a number of developers.
How about if I ask really nicely ;-)
I got this working in the end.. was more straight forward than I thought. Just looking at adding some other features to it... But it works ok
Now I know its not the most secure method... but thats another conversation.
Cheers
That's good news - was worried that changes to FB might render this old'ish tutorial redundant.
Did you follow the tutorial directly or were there any workarounds you had to use?











Hi!
Thank you very much for this nice tutorial. I will give it a try as I see this as a good feature for android games and Iphoen as well.
Best wishes
Michael Hartlef
http://www.whiteskygames.com
http://www.twitter.com/mhartlef