Class: Teak

Defined in: src/teak.coffee

Variables Summary

Status =
{
  NotAuthorized: 'Teak user has not authorized application.',
  NotCreated: 'Teak user does not exist.',
  Unknown: 'Teak user status unknown.',
  ReadOnly: 'Teak user has not granted \'publish_actions\' permission.',
  Authorized: 'Teak user authorized.',
  Ok: 'Operation successful.',
  Error: 'Operation unsuccessful.'
}

Instance Method Summary

Instance Method Details

# (Boolean) init(appId, apiKey, debug = false, w = null)

Initialize the Teak SDK.

Parameters:

  • appId ( String ) Your Facebook/Teak Application ID.
  • apiKey ( String ) Your Teak API Key. This can be retrieved from your game settings.
  • debug ( Boolean ) Enable debug mode, which will perform additional validation and logging. This should not be used in production.

Returns:

  • ( Boolean ) — Always returns true.

# (void) asyncInit(callback)

Add a callback to be executed after Teak and Facebook have been initialized.

If Teak and Facebook have been initialized when this method is called, the given callback will be executed immediately. Otherwise it will be executed on the later of Teak or Facebook being completely initialized.

All callbacks are guaranteed to be executed after window.fbAsyncInit has been executed.

Parameters:

  • callback ( Function void() ) The callback to execute

# (void) on(event, callback)

Add a callback to be executed when a specific event occurs. Available events are requestsAvailable -- Triggered when it is now possible for the user to send requests

# (void) setUdid(userId, partOfIdentify = false)

Set the user's ID without initiating a session.

This should be used when you are dealing with feed post and request clicks. Call setUdid with the user's known ID, then call acceptRequest() or reportFeedClick() as necessary. This will ensure that Teak properly tracks new users/returning users from requests and clicks. Afterwards identify() must be called to initiate a session.

Parameters:

  • userId ( String ) The user's ID.

# (void) identify(userId, accessToken, callback)

Set the user's ID and initiate a session.

Parameters:

  • userId ( String ) The user's ID. This should be the ID you use to identify the user in your backend system or CRM
  • accessToken ( String ) The most recent Facebook access token for the user. This access token must be valid.
  • callback ( Function void (Teak.Status) ) Optional callback.

# (void) postAchievement(achievementId, callback)

Post an achievement.

All achievements are defined under the 'earn an achievement' story in your game's OpenGraph settings. This call cannot be used to post any other stories.

Parameters:

  • achievementId ( String ) The object instance identifier of the achievement to be posted
  • callback ( Function void(Teak.Status) ) Optional callback.

# (void) postHighScore(score, callback)

Post a high score for the user.

I'm sorry, that's just how Facebook does it...

Parameters:

  • score ( Integer ) The user's score. Yes, it's an integer, and yes, you only get one per user per game.
  • callback ( Function void(Teak.Status) ) Optional callback.

# (void) trackEvent(actionId, objectTypeId, objectInstanceId, properties, callback)

Track that an arbitrary action occured.

We ask that you stay below ~200 unique actionId, objectTypeId and objectInstanceIds though there is no enforced limit.

Parameters:

  • actionId ( String ) The identifier for the action, e.g. 'complete'.
  • objectTypeid ( String ) The type of object that is being posted, e.g. 'quest'.
  • objectInstanceId ( String ) The specific instance of the object, e.g. 'gather-quest-1'

# (void) postAction(actionId, objectTypeId, objectInstanceId, properties, callback)

Post a custom open graph action.

This method is used to post all custom actions, either as explicitly shared, implicitly shared, with a user message, with custom variables, or via the Facebook Share Dialog

Parameters:

  • actionId ( String ) The identifier for the action, e.g. 'complete'. Refer to the 'Get Code' feature of the story you're implementing to get the correct identifier.
  • objectTypeid ( String ) The type of object that is being posted, e.g. 'quest'. Refer to the 'Get Code' feature of the story you're implementing to get the correct identifier.
  • objectInstanceId ( String ) The identifier for the specific instance that should be posted. This is the value next to the '#' above every object in a story list.
  • properties ( Object ) Additional properties for this post. This will include any user specified messages, if the post is explicitly shared, and custom variables which the post may rely on
  • callback ( Function void(Teak.Status) ) An optional callback

Options Hash: (properties):

  • fb:explicitly_shared ( Boolean ) Set to true if the user has explicitly opted in to making this post. Set to false if the user has explicitly opted out of making this post.
  • user_message ( String ) Set this to any message the user has provided for this post.

# (void) canMakeFeedPost(objectInstanceId, callback)

Check if a user is allowed to make a given feed post.

Feed posts may be rate limited to prevent overposting (OpenGraph content is less impacted by overposting). Use this if you want to disable any in game functionality based on if a user will not be share a given post.

Parameters:

  • objectInstanceId ( String ) The identifier of the feed post
  • callback ( Function void(Boolean) ) Will be called with true if the user is allowed to share, false if the user is not allowed to share

# (void) popupFeedPost(objectInstanceId, objectProperties, callback, postMethod)

Post a feed post (also known as a Stream Publish story)

This call is exclusively used to publish feed posts, either auto publishing through the facebook API or by bringing up the facebook feed dialog.

Auto published stories are limited by Facebook to 25 per person per day. Dialog stories have no restriction, but users will find them tiring after a couple.

Parameters:

  • objectInstanceId ( String ) The identifier of the feed post as set in the CMS
  • objectProperties ( Object ) Properties to be templated into the feed post as necessary For example level: user.currentLevel would put the user's current level into the feed post wherever {{level}} is used in the CMS
  • callback ( void Function(Object, Object) ) An optional callback to be called after the post is either made or cancelled The first object will contain details about what was posted, the second object will be Facebook's API response. You can check for the presence of 'post_id' on the second object to determine if the post was made or was cancelled.

# (void) claimReward(rewardId, callback)

Attempt to claim a reward

Parameters:

  • rewardId ( String ) The ID of the reward to claim. This is typically the teak_reward_id URL query parameter.
  • callback ( Function(object) ) The callback will be called with information about the attempt to claim a reward The passed object will be of the following form { metadata: {...}, response: {status: "grant_reward", reward: {"Item Name": 2, "Other Item Name": 4}}} response.status may be one of grant_reward - The user was given the reward self_click - This reward is from a post the user made themselves already_clicked - The user has already claimed this reward too_many_clicks - This reward has already been claimed by its maximum number of users exceed_max_clicks_for_day - The user has already claimed their maximum number of rewards of this type for the day invalid_post - Teak did not recognize this reward id response.reward will only exist if response.status is grant_reward

# (void) sendRequest(templateIdentifier, type, giftId, properties, recipients, callback, postMethod)

to use for this request. This controls the message text (possible other stuff TBD) or the staff gate that this request is for. to all recipients. Will receive a list of users who the request was sent to, and a list of recipients that the request could not be sent to

Parameters:

  • templateIdentifier ( String ) The identifier of the CMS template
  • type ( String ) One of the following: "send", "ask", "invite", "gate"
  • giftId ( String ) The identifier of the gift to be gifted or requested,
  • properties ( Object ) A set of properties to be templated into the message (e.g. giftName)
  • recipients ( Array<String> ) The Facebook IDs or invite tokens of the people to send this request to.
  • callback ( Function(Array<String> success, Array<String> fail) ) A callback which will be executed after the request has been sent

# (void) loadInboxData(callback, updateCallback, fbDataLoader)

This will only be executed once for each call made to loadInboxData() player has received since updateCallback was last called. updateCallback will not be called until at least 30 seconds after callback has been called. updateCallback will also include the number of remain gift accepts the user can have, e.g. {"giftLimit": 20}. In the event a day rolls over updateCallback's giftLimit will go up.

Parameters:

  • callback ( Function Array<Object> ) The callback will be called with an array of inbox objects, example given below
  • updateCallback ( Function Array<Object> ) This callback will be executed periodically with new inbox objects which the

# (void) acceptRequest(requestId, callback)

# (void) deleteRequest(requestId)

# (void) hasRequestOfOpportunity(opts, callback)

# (void) sendRequestOfOpportunity(callback)

# (void) reportAdClick(adId)

    Quickly fuzzy find classes, mixins, methods, file:

    Control the navigation frame:

    You can focus and blur the search input: