Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kongregate/kompatible
An api for hosting games on both Kongregate and Facebook
https://github.com/kongregate/kompatible
Last synced: about 2 months ago
JSON representation
An api for hosting games on both Kongregate and Facebook
- Host: GitHub
- URL: https://github.com/kongregate/kompatible
- Owner: kongregate
- License: mit
- Created: 2011-04-04T21:11:58.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2012-06-27T21:43:25.000Z (over 12 years ago)
- Last Synced: 2024-03-26T07:10:45.919Z (10 months ago)
- Language: PHP
- Homepage: http://www.kongregate.com/games/towski/facebook-example
- Size: 137 KB
- Stars: 12
- Watchers: 34
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kompatible
An api for hosting games on both Kongregate and Facebook. The full example is in index.php.
Example app:
[on Facebook](http://apps.facebook.com/kongregate_example/) | [on Kongregate](http://www.kongregate.com/games/towski/facebook-example)To use just the kongregate api library, see: [KongregatePlatform.php](kompatible/blob/master/KongregatePlatform.php)
## Handling kongregate and facebook credentials.
You'll need your application credentials from both Facebook and Kongregate. You can get your Kongregate game credentials at /games/< username >/< game >/api. Then, depending on if the request is from Kongregate or Facebook, we will initialize our $kompatible object differently.
if (isset($_REQUEST['platform']) && $_REQUEST['platform'] == "fb") {
$kompatible = new FacebookPlatform($config['facebook']);
} else {
$kompatible = new KongregatePlatform($config['kongregate']);
}
I've added a configuration file, config.json.example, for storing both credentials.In your Facebook app settings, you'll want to add ?platform=fb to the end of your canvas address.
## User login
Then we'll want to make sure the user is logged in. If they aren't, they will be redirected to the site specific login form.
$kompatible->login();
Once the user is logged in, we can access data through the $kompatible$kompatible->getUserName();
$kompatible->getFriends(); //returns empty array for Kongregate## Load the Site Specific API
If your game needs to use the site specific javacript api (to submit stats, make purchase requests, etc) then we'll need to load those libraries:
$kompatible->loadLibraries();
## Serving your game file
For flash games, you should customize the $kompatible->getFlashParams() function. These are the parameters to pass along to the flash game itself.
public function getFlashParams() {
$params = "&user_id={$this->user}";
return $params;
}Then you can display the flash file in the page with:
$kompatible->displayFlashFile();
## Getting friendsFor both apis, there is a function for getting the friends list:
$kompatible->getFriends();
which returns a similar array for both cases: ("data" => array(array("name" => "username", "id" => "username")...))## Kongregate Microtransactions
KongregatePlatform.php is setup to check the api on first request to see if the user has purchased any items.
If they do, then we automatically mark all the items as used.
First, we get a list of all our available items from the server. (/games/< username >/< game >/items)
$kompatible->getGameItems();
We can get a users specific inventory:
$data = $kompatible->getKredsInventory();
$data['items']
If we want to mark all the items as used:$kompatible->updateInventory();
Or if we want to use a single item on page load:
$kompatible->useKredItem($itemData);The Kongregate microtransaction docs are here: [microtransactions api](http://www.kongregate.com/developer_center/docs/microtransaction-client-api "Transaction API Docs").
## Examples
index.php is the basic example with login and microtransactions
## TODO
* Add a generic version of the FB request dialog calls.
* Comments
* Better demo of platform features
* Styling
* Add tests## Note on Patches/Pull Requests
* Fork the project.
* Make your feature addition or bug fix.
* Add tests if you want
* Commit
* Send me a pull request. Bonus points for topic branches.## Copyright
Copyright (c) 2011 metal games, kongregate. See LICENSE for details.