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.
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.
REST is a style of software architecture that provides a convenient and consistent approach to requesting and modifying data.
The term REST is short for "Representational State Transfer." In the context of Google APIs, it refers to using HTTP verbs to retrieve and modify representations of data stored by Google.
In a RESTful system, resources are stored in a data store; a client sends a request that the server perform a particular action (such as creating, retrieving, updating, or deleting a resource), and the server performs the action and sends a response, often in the form of a representation of the specified resource.
In Google's RESTful APIs, the client specifies an action using an HTTP verb such as
DELETE. It specifies a resource by a globally-unique URI of the following form:
Because all API resources have unique HTTP-accessible URIs, REST enables data caching and is optimized to work with the web's distributed infrastructure.
For more information about REST, you may find the following third-party documents useful:
- Building Web Services the REST Way, which is aimed at service providers but provides a good overview of REST
- HTTP 1.1 method definitions; specification for
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.
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.
- Want to know more about the current user? Try making a call to Players.get
'me'as the ID.
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.
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