Developers › Game Developer Documentation › In-Game API
In-Game API
Overview
This document describes the functions, messages and events available to game developers from the Heyzap in-game API, also known as HeyzapTools.
If you are looking to get started integrating with Heyzap, you should check out our Integration Tutorials first.
API Contents
Functions
Messages
Events
Functions
This is the core of the API. Use these methods to load the library, setup event listeners and send messages to Heyzap.
HeyzapTools.addEventListener
Attach a function to listen for an event from Heyzap. Events are triggered in response to messages you send Heyzap and after actions by the player.
Check out the events section of the api to see which events you can recieve from Heyzap.
Example:
HeyzapTools.addEventListener("loggedIn", function (response:Object) {
// The contents of the response object differs per event
trace("User is now logged in!: " + response.hz_sig_hz_name);
});
HeyzapTools.load
Loads the Heyzap tools.
Parameters:
-
game_key
(String)
-
clip
(MovieClip)
Example:
import heyzap.as2.*;
HeyzapTools.load({game_key: "yourgamekeyhere"});
HeyzapTools.removeEventListener
Remove an event listener function that was attached with addEventListener.
Example:
HeyzapTools.removeEventListener("loggedIn", myLoginHandlerFunction);
HeyzapTools.send
Send a message to Heyzap to initiate user login, sharing, inviting and purchases.
Check out the messages section of the api to see which messages you can send to Heyzap.
Example:
HeyzapTools.send("login");
Messages
Use messages to initiate contact with the API. Some messages control the user interface others request user information or track analytics.
invite
Privately invite a user's friends to play the game. You can also make other private friend graph requests, for example "neighbor" requests, using this message.
Sending the invite message will launch a new browser window which allows users to select which friends to invite, and to further customize the invite message being sent.
If you are converting your Facebook game to work on the rest of the web, you should replace any usage of Facebook's fb:request-form with a call to Heyzap's invite message.
Parameters:
-
friend_selector_title
(String)
Invite Your Friends To Play Taco Towers! -
request_body
(String)
Request body (Default: "Hi friend! Come be my friend in game name!") -
exclude_user_ids
(String)
Comma separated list of user ids to exclude from the list -
custom_data
(String)
Custom tracking string for this invite
Example:
HeyzapTools.send("invite", {
friend_selector_title: "Invite Your Friends To Play Taco Towers!",
request_body: "Hi friend! Come be my neighbor in Taco World!",
exclude_user_ids: "Zm9vYmFyMms=,vYe8mFyMms",
custom_data: "invite-tacos"
});
login
Starts the authentication process for the user currently playing your game. When the user has logged in, we'll fire the loggedIn event to let the game know that normal gameplay can continue.
If the current user is already logged in, we'll fire the loggedIn event right away, otherwise we'll show a login screen.
You can optionally specify a position for the login screen using the x and y parameters, otherwise the screen will be centered over your game.
Parameters:
-
x
(Number)
-
y
(Number)
Example:
HeyzapTools.send("login");
payments
Allow the current player to purchase in-game currency by launching a payments page.
Example:
HeyzapTools.send("payments");
share
Publically share a user's in-game action to their social network wall or stream. You'd typically perform a share when something interesting or significant happens in your game, for example when a player levels up.
If you are converting your Facebook game to work on the rest of the web, you should replace any calls to Stream.publish with Heyzap's share message.
Most of the parameters are optional, but we recommend you supply a call to action, post title, post body and at least one image, to increase user engagement
Parameters:
-
title
(String)
Call to action text on the share dialog -
post_title
(String)
Title of event which will appear in the stream -
post_body
(String)
Additional text to appear in the stream -
images
(Array)
Array of URL strings for multiple image attachments -
custom_data
(String)
Custom tracking string for this share
Example:
HeyzapTools.send("share", {
title: "Show Off Your Achievement",
post_title: "Paul Made 30 Tacos",
post_body: "Paul made 30 tacos, and is now an adept chef!",
images: ["http://www.heyzap.com/images/taco.jpg"],
custom_data: "fbshare-30tacos"
});
Events
Intercept events to handle responses to your actions, and your user's actions. Events generally contain information about the UI, player, in-game items and achievements.
loggedIn
This event is fired when the user playing your game has logged in. You should listen for this event if you require your players to log in before playing, and you must also send the login event to Heyzap.
The response object contains signed parameters, so it is possible for you to verify the authenticity of the response.
Response Parameters:
-
hz_sig_user_id
(String)
A unique user id for this user -
hz_sig_email
(String)
The user's email address -
hz_sig_name
(String)
The user's full name -
hz_sig_profile_pic_square
(String)
A square profile picture for this user -
hz_sig_profile_pic_big
(String)
A large profile picture for this user -
hz_sig_profile_pic_small
(String)
A small profile picture for this user -
hz_sig_facebook_uid
(String)
The user's facebook uid if they are connected with facebook -
hz_sig_time
(String)
A timestamp to help against replay protection -
hz_sig
(String)
A signature formed from these params, see the signatures docs for more info
Example:
HeyzapTools.addEventListener("loggedIn", function (response:Object) {
trace("User is now logged in!: " + response.hz_sig_username);
});
paymentComplete
This event is fired when the user playing your game has completed a currency purchase. You should listen for this event if you wish to update a counter of in-game currency, or show a purchase confirmation dialog in your game.
The response object contains signed parameters, so it is possible for you to verify the authenticity of the response.
Response Parameters:
-
hz_sig_user_id
(String)
A unique user id for this user -
hz_sig_amount_purchased
(String)
The amount of your currency the user just purchased -
hz_sig_time
(String)
A timestamp to help against replay protection -
hz_sig
(String)
A signature formed from these params, see the signatures docs for more info
Example:
HeyzapTools.addEventListener("paymentComplete", function (response:Object) {
trace("Payment complete!")
trace("- User's unique id: " + response.hz_sig_user_id);
trace("- Currency just purchased: " + response.hz_sig_amount_purchased);
});