Need Help? developers [at] socialgn.com

Home | SGN Home | Developer Blog

The SGN API Documentation, version 0.4

The SGN API currently exposes 5 methods which you can call with the API Client. Responses are encoded with JSON. You do not need to check whether a user has added the Social Gaming Network application or not; the API accepts updates for all users.

In PHP, the client object is created with the following code:

// PHP Example
$SGN = new SGN_Client( API_KEY, SGN_SECRET, 'facebook' );

In this example, API_KEY is the Facebook API key for the application, and SGN_SECRET is the SGN secret key which you can find in the SGN Developer application under “My Games.”

fat_bar

Generate the IFRAME for an fb:iframe or standard iframe tag for the SGN Social GameBar. This new version uses a couple parameters:

// PHP Example
// $canvas = true for canvas apps, false for iframe apps
// $style = 'light' for light color scheme, 'dark' for dark color scheme

echo $SGN->fat_bar(true, 'light');

As always, it is essential to use this call to ensure that the correct parameters are generated. This bar shows relevant data to users, so while you are welcome to cache the result of this method in your views, you should not cache it for longer than 5 minutes.

get_bar

Generate the IFRAME SRC for an fb:iframe or standard iframe tag. In order to receive credits for giving clicks to other games, you must use this method to generate the correct SRC parameters. You can then cache the result in the views of your application.

// PHP Example  
echo "<fb:iframe " . $SGN->get_bar() . "/>"; // for fb:iframe  
echo "<iframe " . $SGN->get_bar() . "></iframe>"; // for iframe

post_newsFeedUser

Publish a templatized news feed story for a user, using a format similar to the templatized stories in the Facebook API. Story templates must be registered through the SGN Developer application. Currently, each application is allotted up to four templates. In a template, tokens are marked with curly braces:

$story = 'defeated {target} with {weapon} in the {url}Fight Club Colloseum{/url}'

There are two reserved tokens: {target} and {url}, {/url}. The rest are up to your application. To define the data for a token, you pass an associative array or dict for the “data” parameter. For the previous template, the data might be:

$data = array('weapon'=>'ninja star','url'=>'arena.php');

For the target token, you use the “targets” parameter to give an array of users mentioned in the story (not included the user the story belongs to:

$targets = array(431243);

The whole example would then look like:

// PHP Example  
$story = 'defeated {target} with {weapon} in the {url}Fight Club Colloseum{/url}';
$data = array('weapon'=>'ninja star','url'=>'arena.php');
$targets = array(431243);
$SGN->post_newsFeedUser($user, $story, $data, $targets);

If this template has not been registered in the SGN Developer application, this call will return an error.

post_statsUser

Post stats defined in the SGN Developer application, up to four per game. These are basic string values that can represent any kind of stats a user of your game may have. If you have defined the stat names and you post stats for a user, they will get a box with their stats for your game in their SGN Profile.

// PHP Example
$SGN->post_statsUser($user, "$value_1", "$value_2", "$value_3", "$value_4");

post_scoreUser

Post an integer value for a user’s score in your game. This could be their highest score in a Flash game, their total wins in a competitive game, or their experience points in an RPG. This will allow us to build leaderboards for your game.

// PHP Example
$SGN->post_scoreUser($user, $score);

check_isHubUser

Check if a user has added the Social Gaming Network application. This is not necessary for any of the above methods, but it will be necessary for future portions of the API.

// PHP Example
if( $SGN->check_isHubUser($user) ) {
// do something...
}

More methods will be available soon! Watch the blog for updates and fresh versions of our API client libraries.