Welcome to web game development with the Google Play games services!
The Google Play games services provides cross-platform APIs that let you easily integrate popular gaming features such as achievements and leaderboards in your web-based games.
This guide describes how to enable Google Play games services for your web-based games.
Introduction
The REST API for Google Play games services allows you to issue REST calls to set and retrieve game services data from your web game. You can also use the Management API to make REST calls to reset the game services data and perform other administrative functions.
Finding sample code
Links to sample code are available on the samples download page. You will need to set up your own versions of these games in the Google Play Developer Console before they can work properly.
Communicating with Google Play games services
There are two ways you can communicate with Google Play games services.
In a client-only setup, your game only communicates with Google Play games services through the browser using JavaScript. This is the technique you typically will use if you are creating a simple Flash or HTML5 game that doesn't rely on a backend server for any game logic.
To enable Google Play games services in a client-only setup, follow the Client-Only Setup instructions.
In a client-server situation, your game typically communicates with Google Play games services from your server using a server-side language such as Java, Ruby, or PHP, although you can still communicate client-side if you wish. This is the technique you typically will use if you are creating a game that uses a backend server for much of your game logic, such as an MMO or a simulation game.
To enable Google Play games services in a client-server setup, follow the Client-Server Setup instructions.
Common REST calls
Ready to make a game? Here are some of the more common calls you might need to make.
Player
- Want to know more about the current user? Try making a call to Players.get
with
'me'
as the ID.
Achievements
Make sure you review the Achievements guide, which explains achievements in more detail.
- Want to get a list of current achievements? You can make a call to AchievementDefinitions.list...
- ...then combine that with a call to Achievements.list to find out which ones the player unlocked.
- Did the player earn an achievement? Use Achievements.unlock to unlock it!
- Did the player make progress towards a partial achievement? Use Achievements.increment to report progress (and find out if the player unlocked it).
- Are you debugging a game that is not yet in production? Try calling Achievements.reset or Achievements.resetAll from the Management APIs to reset achievements to their original state.
Leaderboards
Make sure you review the Leaderboards guide, which explains leaderboards in more detail.
- Want to get a list of all scoreboards in the game? Make a call to Leaderboards.list.
- Is the player done with a game? You can submit their score to Scores.submit and find out if this is a new high score.
- Want to display a leaderboard? Get the data from Scores.list and show it to the user.
- Use Scores.listWindow to find an assortment of scores close to the user's high score.
- To get more information about the player's score in a particular leaderboard (for example, if the player is in the top 12% of all players), call Scores.get.
- Are you debugging a game? Try calling Scores.reset from the Management APIs to reset all scores for that player from a particular leaderboard