Social Integration
We're trying to make social integration easy, here's how you can implement posting to a users' Facebook, Twitter, and Clay.io all with just a few lines of code.
Right now we have integration with Facebook, Twitter and Clay.io. For all three, your players will have to be logged into Clay.io to post, and will have to grant your game the permission to post (once). It's on our todo list to not require them to be logged into Clay.io.
Posting Messages
The integration for each is identical:
var fb = new Clay.Facebook();
fb.post( { message: 'Whatever the message you want to post is' }, function(obj) {
// Optional callback
console.log( obj );
} );
Note that you can also pass any of the parameters you would normally be able to pass with the Facebook Graph API listed here. For example, if you wanted to post a screenshot of the game's current state, the code would look something like this:
var screenshot = new Clay.Screenshot( { prompt: false } );
screenshot.save( function( response ) {
(new Clay.Facebook()).post( { message: "I just scored " + score + " in Test Game!", picture: response.imageSrc } );
} );
var twitter = new Clay.Twitter();
twitter.post( { message: 'Whatever the message you want to post is' }, function(obj) {
// Optional callback
console.log( obj );
} );
Clay.io Stream
var stream = new Clay.Stream();
stream.post( { message: 'Whatever the message you want to post is' }, function(obj) {
// Optional callback
console.log( obj );
} );
Editable Messages
If you would like to allow the user to edit your message, pass the option editable.
// Note that this works for Facebook and Twitter post methods as well
var stream = new Clay.Stream();
stream.post( { message: 'Whatever the message you want to post is', editable: true }, function(obj) {
// Optional callback
console.log( obj );
} );
Inviting Users with Facebook
Note: You must have a Facebook App setup for your game, for this to work.
You can allow your users to invite their Facebook friends to play your game using Clay.Facebook.invite(). Calling this method will bring up a modal window that lists the player's Facebook friends, allowing them to individually select the ones they wish to send invites to. Upon clicking the "Invite" button, posts will be made to the walls of the friends they selected with a link to your game, the game's description, and a developer-specified caption. If no caption is specified, the default is: Come play game-name with me!
Here is an example of how you would call up the invite window, and specify a unique caption to post:
// Do note that this will link to your game on Clay.io, so be sure to upload and publish!
Clay.Facebook.invite( { caption: "Come play me in this sweet game!", function() {
console.log( "This is called when at least one friend is successfully invited." );
} );
If you would like to bypass the modal window and simply have the UI show up in a DOM element, simple add the id option, so your first parameter would be something like { id: 'container-id', caption: 'whatever you would like' }, and the contents would be placed in <div id='container-id'>
Provide Feedback
We take customer support, and the quality of our developer tools and documentation very seriously. We want to hear how you think we can improve our documentation! Let us know if anything is missing, or unclear on this documentation page, and we'll get that fixed!