Google Play Games Services V1🔗

Google Play Games Services V1 - a set of services that allows your users to log in, track their best results in the leaderboard, compare their achievements, invite friends to play the game. Applications may include any or all of the following features supported by Google Play Games:
- Leaderboards — compares scores with player friends and other players from around the world
- Achievements — Scores are awarded to players in the Google Play Games Achievement Tracking System. Players can earn scores by completing certain in-game tasks. Players cannot use the section for anything else but to evaluate the progress in the games. It was designed so that players can communicate and compete with each other.
Pre-setup🔗
Setting up Google Play Games consists of two steps:
- Connect Google Play Games to the project
- Connect Google Sign-in for authorization in Google Play Games
Connecting Google Play Games in the Google Play console🔗
- Open the Google Play Developer Console
- In the list on the left, select "Game Services"

- Click the "Add New Game" button

- Follow the instructions in the settings window, and then click "Save"
- In the menu on the left, select “Linked apps”
- Click the "Android" button

- In the "Package name" section, enter the package name of your application, then select it
- Click the "Save and continue" button (Save), and then convince the correctness of the code of the certificate of your application
- Click the "Authorize" button to complete linking your game project with your game

- Verify that the packagename and sha1 checksum certificates are correct
- Open the "Game Details" section. Copy the ID of your application (displayed under the name of your game, as indicated in the image), you will need it in the next step

Now you need to edit the AndroidManifest.xml file
In the <application> section, you need to add meta information and specify the ID of your application obtained in the previous step. ATTENTION! In order for the ID to be perceived by the system as a string, and not as an integer, the front ID must specify the service unicode symbol \u003. Example for ID 987654321012
<application
...>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="\u003987654321012"/>
Connect Google Sign-In🔗
- Open page Google Sign-In for Android
- Go directly to "2" Configure a Google API project and click "Configure a Project"

- Select your project in the drop-down list. If you don’t find him there, then something is wrong. Make sure you are logged into Google under the same account under which you go to the Google Play console

- Enter the package name and sha-1 fields of the certificate checksum with which you sign the release build of the application
- After a message appears indicating that the operation completed successfully, click on the "API Console" link and go to the Google Developers console

- In the window that opens, you will see a list of OAuth clients. One (Android) was generated when you linked the created Google Games to your project in the Google Play console. The second (Web) was generated in the previous step, during the setup of Google Sign-In. This client ID must be copied for further configuration.

For SDK version v6.x and above
Starting with SDK v6.x, the MRGSAuthenticationGoogleSignIn module is no longer part of the MRGSAuthentication module and requires a separate connection:
Add dependencies🔗
Add the MRGS SDK to the project:
Unity:
Adding to the project (general instruction)
Step 1. Add Sources
To add MRGS to a project via the Unity Package Manager (available from Unity 2018+) simply add a scopedRegistries section to the Packages/manifest.json file by adding the following entry:
{
"dependencies": {
...
},
"scopedRegistries": [
{
"name": "MRGS",
"url": "https://mrgs-nexus.my.games/repository/mrgs-uninty-plugins/",
"scopes": [
"games.my.mrgs"
]
}
]
}
Alternatively, you can click Edit -> Project Settings -> Package Manager -> '+' in scoped registry section, and fill in the fields according to the data above.
Step 2. Add dependency
- Click
Window -> Package Manager -> select 'Packages: MyRegistries' from dropdown list, select packageMRGSAuthenticationGoogleSignInfrom the list, then click "Install" - Import the module:
using MRGS;
- Download the latest version of the library. Unzip the archive.
- (For unitypackage integration) In Unity, click
Assets -> Import Package -> Custom Package, and select thegames.my.mrgs.authenticationgooglesignin.unitypackagepackage from the downloaded archive. - (For tgz integration) In Unity, click
Window -> Package Manager -> '+' -> Add package from tarball, and select thegames.my.mrgs.authenticationgooglesignin-<version> package. tgzfrom the downloaded archive. - Import the module:
using MRGS;
Android:
Adding to the project
Add a dependency in build.gradle file:
Copy the MRGSAuthentication.aar MRGSAuthenticationGoogleSignIn.aar files into the libs directory of your project. Add the dependencies into the build.gradle file.
dependencies {
//...
implementation(name: 'MRGSAuthentication', ext:'aar')
implementation(name: 'MRGSAuthenticationGoogleSignIn', ext:'aar')
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.browser:browser:1.5.0'
implementation "com.google.android.gms:play-services-auth:20.6.0"
implementation "com.google.android.gms:play-services-games:23.1.0"
}
Now you need to specify the received Web Client Id when initializing MRGS
using MRGS;
public class MasterController : MonoBehaviour
{
void Awake()
{
// Setting up mrgs params
// ...
var modulesParams = new List<MRGSExternalSDKSettings>;
modulesParams.Add(new MRGSGoogleSignInParams(WEB_CLIENT_ID));
// Setting up external sdk params
// ...
IMRGSServerDataDelegate loadDelegate =...
MRGService.Instance.Initialize(serviceParams, modulesParams, loadDelegate);
}
}
import games.my.mrgs.MRGServiceParams;
import games.my.mrgs.MRGSModuleParams;
import games.my.mrgs.MRGService;
import games.my.mrgs.authentication.google.signin.MRGSGoogleSignIn;
public class YourApplicationClass extends Application {
@Override
public void onCreate() {
super.onCreate();
final MRGServiceParams serviceParams = ...;
final List<MRGSModuleParams> moduleParams = ...;
// Setting External SDKs
final MRGSGoogleSignInParams googleSignInParams = MRGSGoogleSignInParams.init("GOOGLE_CLIENT_ID");
moduleParams.add(googleSignInParams);
MRGService.service(context, serviceParams, moduleParams);
}
}
Work with MRGSAuthentication interface🔗
To work with the Google Play Games, use the MRGSAuthenticationGoogleSignIn class. Please note that this class implements main interface MRGSAuthentication, so it includes all the methods of this interface. The following describes the standard implementation of the MRGSAuthentication interface:
Check authorization status (whether the user is logged in):
For regular login use one of the methods:
import android.app.Activity;
import androidx.annotation.NonNull;
import games.my.mrgs.MRGSError;
import games.my.mrgs.authenticationMRGSCredentials;
import games.my.mrgs.authentication.MRGSLoginCallback;
import games.my.mrgs.authentication.google.signin.MRGSGoogleSignIn;
MRGSGoogleSignIn.getInstance().login(activity, new MRGSLoginCallback() {
@Override
public void onSuccess(@NonNull MRGSCredentials credentials) {
// Handle result.
}
@Override
public void onError(@NonNull MRGSError error) {
// Handle error.
}
});
To get all the information about the current authorization status, user information, authorization status, use the methods:
//An object is returned that combines information about the user (identifier, name, email, etc.) and about the token.
MRGSAuthenticationGoogleSignIn.Instance().GetCredentials((MRGSAuthenticationCredential credentials, MRGSError error) => {
string resultDescription = "getCredentials:\nCredentials: " + credentials + "\nError:\n" + error;
MRGSLog.getInstance().addLog("MRGSAuthentication<Unity> - AppleGameCenter " + resultDescription);
if (!error) {
// Credentials data work
}
});
//Information about the user, identifier, name, email, etc. is returned separately.
MRGSAuthenticationGoogleSignIn.Instance().GetCurrentUser((MRGSAuthenticationUser user, MRGSError error) => {
string resultDescription = "getCurrentUser:\User: " + user + "\nError:\n" + error;
MRGSLog.getInstance().addLog("MRGSAuthentication<Unity> - AppleGameCenter " + resultDescription);
if (!error) {
// User data work
}
});
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import games.my.mrgs.MRGSError;
import games.my.mrgs.authentication.MRGSAccessToken;
import games.my.mrgs.authentication.MRGSAuthentication;
import games.my.mrgs.authentication.MRGSUser;
import games.my.mrgs.authentication.google.signin.MRGSGoogleSignIn;
import games.my.mrgs.utils.optional.BiConsumer;
// Returns user's information.
MRGSGoogleSignIn.getInstance().getCurrentUser(new MRGSAuthentication.UserCallback() {
@Override
public void onSuccess(@NonNull final MRGSUser user) {
}
@Override
public void onError(@NonNull MRGSError error) {
}
});
// Returns authentication's information.
MRGSGoogleSignIn.getInstance().getAccessToken(new BiConsumer<MRGSAccessToken, MRGSError>() {
@Override
public void accept(@Nullable MRGSAccessToken accessToken, @Nullable MRGSError error) {
if (error != null) {
Log.d("MRGSAuthentication", "AccessToken error: " + error.getErrorText());
} else {
Log.d("MRGSAuthentication", "AccessToken success: " + accessToken);
}
}
});
In order to "log out" of a user’s account, use the method:
Additional features of Google Play Games🔗
Also, MRGSAuthenticationGoogleSignIn (MRGSGoogleSignIn on Android) offers you some additional features
In order to get a user avatar with a given identifier, use the method:
import android.graphics.Bitmap;
import androidx.annotation.NonNull;
import games.my.mrgs.MRGSError;
import games.my.mrgs.authentication.MRGSAvatarCallback;
import games.my.mrgs.authentication.MRGSUser;
import games.my.mrgs.authentication.google.signin.MRGSGoogleSignIn;
// Call #getCurrentUser() to get current user.
final MRGSUser user = ...
// Get user's avatar.
MRGSGoogleSignIn.getInstance().getUserAvatar(user, new MRGSAvatarCallback() {
@Override
public void onSuccess(@NonNull Bitmap bitmap) {
// Handle result.
}
@Override
public void onError(@NonNull MRGSError error) {
// Handle error.
}
});
Work with achievements🔗
Wor with achievements is described in the section Work with player achievements (Achievements).
Created: 2020-05-28