デバイス ID でのログインを実装する
Overview
You can use a device ID—such as computer's serial number, the International Mobile Equipment Identity (IMEI) of a mobile device, or another unique device identifier—to log into AccelByte Gaming Services (AGS) and gain access to its features. Device ID logins don't require account credentials, making them ideal for getting up and running quickly, and can be used for testing purposes or mobile games.
This guide will show you how to implement device ID logins into your game.
AccelByte recommends using more secure login methods for shipped games. Use caution if you intend to use this login method after your game is released.
Prerequisites
To complete this guide, you will need:
- To have completed the previous Getting Started guides.
- An Unreal or Unity project.
Configure a login method in the Admin Portal
You need to set up a login method in the AGS Admin Portal so you can connect it to your project.
From the AGS Admin Portal dashboard under your project's game namespace, go to Game Setup > 3rd Party Configuration > Auth & Account Linking.
On the Login Methods page, click on the + Add New button.
From the list of login methods, select the Device.
On the pop-up, fill in the Redirect URI field with
http://127.0.0.1
. This is the only field you need to fill in. Once done, click Create.On the Login Platform Configuration page, verify the Status is set to ACTIVE. If it's not, click Activate next to Integration, and confirm on the activation on the pop-up that appears.
Your login method has been configured in the AGS Admin Portal.
Implement device ID logins into your game
Paste the code below for your chosen engine wherever you intend to call your logins.
- Unreal Engine
- Unity
Be sure to #include
the following libraries wherever you integrate the device ID logins code:
#include "OnlineSubsystemAccelByte.h"
#include "OnlineSubsystemAccelByteTypes.h"
#include "OnlineIdentityInterfaceAccelByte.h"
IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get(ACCELBYTE_SUBSYSTEM);
ensure(Subsystem != nullptr);
FOnlineIdentityAccelBytePtr IdentityInterface = nullptr;
ensure(FOnlineIdentityAccelByte::GetFromSubsystem(Subsystem, IdentityInterface));
int32 LocalUserNum = 0;
FOnlineAccountCredentialsAccelByte Credentials{ EAccelByteLoginType::DeviceId, TEXT(""), TEXT("") };
// Login
IdentityInterface->AddOnLoginCompleteDelegate_Handle(LocalUserNum
, FOnLoginCompleteDelegate::CreateLambda([](int32 LocalUserNum, bool bLoginWasSuccessful, const FUniqueNetId& UserId, const FString& LoginError)
{
if (bLoginWasSuccessful)
{
// Do something when player successfully logged in
}
else
{
// Do something when player failed to log in
}
})
);
IdentityInterface->Login(LocalUserNum, Credentials);
Be sure you are using
the following library wherever you integrate the device ID logins code:
using AccelByte;
string emailAddress = "yourEmailAddress";
AccelByte.Core.ApiClient apiClient = AccelByte.Core.AccelByteSDK.GetClientRegistry().GetApi(emailAddress);
AccelByte.Core.ResultCallback<AccelByte.Models.TokenData, AccelByte.Models.OAuthError> loginCallback = loginResult =>
{
if (!loginResult.IsError)
{
// Do something when player successfully logged in
}
else
{
// Do something when player failed to log in
}
};
apiClient.GetUser().LoginWithDeviceId(loginCallback);
Test device ID login implementation
Write log messages in the code comments for success and failure, play your game, and test your login integration. If the log message for success appears, congratulations! You have implemented device ID logins and fully integrated AGS into your project!
You are now ready to explore and implement other AGS offerings into your game. Check out the Services section for detailed information on AGS features, or jump right in and start integrating more by following our step-by-step How-to guides.