# How can you check your users' unlocked achievements (Google Play Game Services)?

Is it possible to see how many of your users have unlocked certain achievements on the Google Play Developer console? This information would be very useful. I guess that one could achieve this through integration with Google Analytics but I was wondering if there was a simpler way to get this data.

The Google Play Games service actually provides an API for doing just that. I have provided an example for querying the state of all achievements in this answer on SO - but I will provide that information here as well.

The following method will retrieve and iterate all achievements, and should be run asynchronously (using AsyncTask or in a separate thread):

public void loadAchievements()  {
GameHelper mHelper;        // GameHelper should be accessible for this to work

boolean fullLoad = false;  // set to 'true' to reload all achievements (ignoring cache)
float waitTime = 60.0f;    // seconds to wait for achievements to load before timing out

PendingResult p = Games.Achievements.load( mHelper.getApiClient(), fullLoad );
Achievements.LoadAchievementsResult r = (Achievements.LoadAchievementsResult)p.await( waitTime, TimeUnit.SECONDS );
int status = r.getStatus().getStatusCode();
if ( status != GamesStatusCodes.STATUS_OK )  {
r.release();
return;           // Error Occurred
}

// process the loaded achievements
AchievementBuffer buf = r.getAchievements();
int bufSize = buf.getCount();
for ( int i = 0; i < bufSize; i++ )  {
Achievement ach = buf.get( i );

// here you now have access to the achievement's data
String id = ach.getAchievementId();  // the achievement ID string
boolean unlocked = ach.getState == Achievement.STATE_UNLOCKED;  // is unlocked
boolean incremental = ach.getType() == Achievement.TYPE_INCREMENTAL;  // is incremental
if ( incremental )
int steps = ach.getCurrentSteps();  // current incremental steps
}
buf.close();
r.release();
}


This assumes you are using BaseGameUtils (and mHelper is already connected). The API documentation should provide any further information you need. You can also do this with callbacks if you don't want to manually run it asynchronously.

You should of course change the internals of the loop which are processing the results to do something more useful, since the example only illustrates how to access the information. For your question you may only need to check for unlocked achievements and count them.

• thanks, I am using BaseGameUtils so your solution should work for me. I was actually hoping for something a bit different though. Almost like an "admin" view of all unlocked achievements, I don't actually want to do this programmatically in my game because I am the only one who should be able to view this data. If there is no such view then I will probably build an "admin" view in the game that I will disable before releasing (or a separate app that only I use) so then I would accept your answer. Although Google Analytics may actually then be an easier option for what I want. Jun 14 '14 at 13:18
• btw do you know if you can view exactly who actually has unlocked which achievements? Or is this against some ToS? I know that you are not allowed to do this using Google Analytics. Jun 14 '14 at 13:19
• Oh I see, I think I misread your original question..my bad. To answer the question (properly), in the Developer Console go to the Game services tab, under Achievements there is a column for Unlocked % / Total # / Time which displays exactly what you are looking for :D Jun 14 '14 at 16:08
• thanks. For some reason this column just shows a "-" for me. I had a look at the other stats pages (e.g. Players) and they just say "More user data needed to display analytics". However, under "Engagement" it does actually show me correct data and I can see that a bunch of achievements have been unlocked. I have only released the game to about 20 people for testing to date (but it is in a production state), any idea how much data needs to be present before these stats are actually shown? Jun 14 '14 at 22:49
• btw I accepted your answer since it is useful and I may use it in the long-term and it would achieve what I wanted as well - although your comment was more useful to me in the short term. Jun 14 '14 at 22:51

# Callback approach

Apart from some small errors in the accepted answer I prefer the callback approach to get the results so we don't have to perform all of this in the background.

To simplify comparison I used the same GameHelper. This GameHelper object is a singleton containing a reference to the GoogleApiClient object.

Updated example code:

    GameHelper mHelper;        // GameHelper should be accessible for this to work
boolean fullLoad = false;  // set to 'true' to reload all achievements (ignoring cache)