it's difficult to share my PHP code directly (i would have to clean and repackage it) but here are the steps (working for Mac/Windows.. and even the mobile devices if you don't want to use the mobiles FB SDKs
:
- you need the facebook PHP SDK (it's free :p) and a PHP Web Server
- Create a Facebook developer profile with your personal facebook account (or another one) (on the facebook website) and create a facebook webapp (mine is "SpeedRacer"). it will give you an app ID and hash key needed by PHP FB API Calls...
- create a PHP FB Login Script which logs you on facebook (if you aren't already loggued, facebook API will redirect you and will eventually ask you if you want to authorize your web app). In your script, you have to pass a parameter to facebook to ask for a facebook
permanent access token for your application (check the API Doc or google for more details).
- In your AppGameKit game, create a complex selfmade random/unique ID (String)(it will be your reference ID during the login process)
- In your AppGameKit Game, open your FB login PHP script with the previous unique ID as a GET variable (with openbrowser() command) and prepare yourself to use the GetResumed() AppGameKit command
- In the web browser (in the login PHP Script), you can (and have to) pass a custom variable which will be returned by facebook once loggued in (the self-generated UniqueID in this case) . When you have the callback from Facebook (so... you are loggued), save in a user database (MySQL?) the UniqueID with the returned Facebook Token in a table (token is needed by almost every FB PHP Commands). Tell the user on your login page (after the FB Login callback) that it can come back to the game.
- In your AppGameKit game, the GetResumed() will be called at this time. You can now use a SendHTTPRequest() on another PHP script with your self-generated UniqueID to retrieve your Facebook permanent Token (and delete the uniqueID in database after ...it's important) . Save it in the AppGameKit game filesystem for future re-use (you can crypt it for more security).
- After that, you can do anything you want by calling PHP scripts or methods on server side with this Token (one PHP script/method to get the FB Profile (fullname, Facebook ID,user infos.. and after ... Profile Picture path.. (i have shared a little explanation on how to download it in another thread :
http://forum.thegamecreators.com/?m=forum_view&t=206002&b=41&msg=2462103#m2462103 ) ), another one to Post on wall , friendslist..). etc...
For the next launches of your game, simply ask your game to do a SendHTTPRequest() with the permanent token on a FB PHP Script (the one which gets the profile) and if something is going wrong with your permanent token, FB will thrown an exception ... so you have to return the error directly from the SendHTTPRequest in your game and your game has to regenerate a uniqueID and re-launch the web browser to login again
if everything is ok and the PHP Script is returning your profile, you have nothing to do (you already have the correct permanent token in your game)
You could also (for security) deal only with your self-generated Unique ID. Your PHP scripts would only have to resolve it to the facebook Token in your database each time. BUT, take care about this "unique" ID which can't be really unique because it's ... a random string.... So this unique ID must have a short lifetime (just the duration webbrowser call for the login and the login callback to your game... so .. few seconds). That's why it's better to keep the FB Token directly and delete the selfmade Unique ID from database as soon as possible .
All the Facebook PHP Functions are well documented in the SDK with a lot of small examples PHP Scripts.
but indeed, It could be cool to create a ready-to-use FB Package with some basics custom AppGameKit functions/Commands (Login(), GetFriendsList(), GetPicture() etc...)for Facebook Mac/Windows Integration
The main problem is that your game become dependant of your personal webserver to have the ability to deal with FB ... but it should be easy for TGC to deal everything with internal scripts to make FB webcalls directly :p (everything behing few AppGameKit commands) ... but yes... it's not very clean ...lol
Or maybe with the FB Javascript SDK (with an AppGameKit internal JVM :p) ... or something else .. (https://developers.facebook.com/docs/sdks/)
--- Ready for FB ?
---