Custom Development
Getting Started
To get started you should download the doppelme library and import it into your application code. You will also need a partner id and partner key if you haven't one alreadyHello World
Once you have the SDK library, you should check connectivity (see if you can return the current version of the API) and then also check permissions. In PHP, you can do this as follows:
//import the doppelme library
require_once("doppelme.php");
//Your partner credentials (replace below with your own partner id and key)
$doppelme_partner_id = 1;
$doppelme_partner_key = '123456abcdefg';
//Set up your api
$doppelme_api = new DoppelMe($doppelme_partner_id, $doppelme_partner_key);
//Simple pre-checks
echo "Version: " . $doppelme_api->version() . "<br>";
echo "Access Allowed: " . $doppelme_api->check_has_permissions() . "<br>";
If you experience problems with access, make sure that your whitelist in your partner area is set up appropriately
Create an Avatar
One of the first things that you might want to do it actually create an avatar for your user. Upon creating an avatar, you will be given the associated DoppelMe Key. You should then store this along with your user's details so that you always reference their avatar.
//Create an avatar for one of your users
//The $my_user_id is a unique id that you use to identify your user
$my_user_id = '1';
$avatar_name= 'First Avatar';
//create an avatar for your user and return the DoppelMe Key for the new avatar
$doppelme_key = $doppelme_api->create_user_account($my_user_id, $avatar_name);
Unlock Items for your User
You can "unlock" items and make them available to users by "purchasing" the item on their behalf. Note this only makes the item available to the user - it does not apply the item to the avatar itself.
//Unlock item 106 for this user. The user will now be able to select
//this item in the editor
$item_id = 106;
$doppelme_api->purchase_item($my_user_id, $doppelme_key, $item_id);
Update Your Users Avatar
Continuing on from above, we now assign an item to the avatar itself. Use this to modify the avatar image.
//Assign item 109 (Ripped Jeans) to this avatar and colour them red.
//If the item costs coins, we will purchase it on behalf of the user
//if they do not already own the item
$item_id = 109;
$colour = 'FF0000';
$purchase = 1;
$doppelme_api->assign_item($my_user_id, $doppelme_key, $item_id, $colour, $purchase);
//Show the avatar image
echo '<img src="http://www.doppelme.com/' . $doppelme_key . '/avatar.png">';
Allocate Coins To Your User
You may want to allocate coins to your users (perhaps as an achievement award):
//Get current number of coins user has
$details = $doppelme_api->get_user_details($my_user_id);
echo "Coins: " . $details['DoppelMeCoins'] . "<br>";
//Allocate another coin and check new total
$num_coins = 1;
$result = $doppelme_api->assign_coins($my_user_id, $num_coins);
if ($result['StatusCode'] != 0) {
echo 'Problem assigning coins (' . $result['StatusInfo'] . ')';
} else {
$details = $doppelme_api->get_user_details($my_user_id);
echo "Coins: " . $details['DoppelMeCoins'] . "<br>";
}
More
For other functionality available, you can look at the list of functions available in the SDK library. If there is something particular that you would like to achieve that you don't think is covered, please let us know and we'll be happy to add it.The latest version of the webservice is always available at http://services.doppelme.com
We have provided code examples above for PHP, but the DoppelMe API can be integrated with almost any language. If you have trouble, we can always try to help you.