Access
Connect cross-platform accounts & identity management
You can use AccelByte Cloud’s .NET (C#) SDK to implement our backend services within your game. The SDK acts as a bridge between your game and our services. This guide will show you how to create an application that uses .NET (C#) Server SDK from scratch.
AB_BASE_URL
environment variable.Confidential
.
Client ID
value for AB_CLIENT_ID
environment variable.Client Secret
value for AB_CLIENT_SECRET
environment variable.Create a new solution and a new console project inside the solution using dotnet
CLI.
$ mkdir -p /path/to/mysolution
$ cd /path/to/mysolution
$ dotnet new sln --name mysolution # Create a new solution: mysolution
$ dotnet new console -o myproject # Create a new console project myproject
$ dotnet sln add myproject/myproject.csproj # Add myproject to mysolution
Get a release version of the AccelByte C# Server SDK (opens new window) and add it as C# project dependency.
Replace {VERSION}
with a specific release version tag (opens new window).
$ git clone https://github.com/AccelByte/accelbyte-csharp-sdk.git # Clone AccelByte C# Server SDK
$ cd accelbyte-csharp-sdk
$ git checkout {VERSION} # Switch to a specific release {VERSION}
$ cp -rv AccelByte.Sdk /path/to/mysolution/AccelByte.Sdk # Copy AccelByte C# Server SDK source code
$ cd /path/to/mysolution
$ dotnet sln add AccelByte.Sdk/AccelByte.Sdk.csproj # Add AccelByte C# Server SDK to solution
$ cd myproject
$ dotnet add reference ../AccelByte.Sdk/AccelByte.Sdk.csproj # Add AccelByte C# Server SDK as a dependency of C# project
TIP
We recommended using the .NET (C#) Server SDK version that matches your AccelByte Cloud version.
$ cd /path/to/mysolution/myproject # Go to project
$ dotnet add package AccelByte.Sdk # Add AccelByte C# Server SDK Package from Nuget
Create an SDK instance, log in using user credentials, and call an AccelByte Basic API in program.cs
.
The DefaultConfigRepository
gets its values from AB_BASE_URL
, AB_CLIENT_ID
, and AB_CLIENT_SECRET
environment variables.
using System;
using System.Collections.Generic;
using AccelByte.Sdk.Core;
using AccelByte.Sdk.Api;
using AccelByte.Sdk.Api.Legal.Model;
namespace AccelByteExample
{
internal class Program
{
static int Main(string[] args)
{
AccelByteSDK sdk = AccelByteSDK.Builder
.UseDefaultHttpClient()
.UseDefaultConfigRepository()
.UseDefaultTokenRepository()
.Build();
bool login = sdk.LoginUser("myUsername", "myPassword");
if (!login)
{
Console.WriteLine("Login failed");
return 1;
}
try
{
List<RetrieveAcceptedAgreementResponse>? response = sdk.Legal.Agreement.RetrieveAgreementsPublicOp.Execute();
if (response == null)
throw new Exception("Response is null");
foreach (var aggreement in response)
Console.WriteLine(aggreement.PolicyName);
}
catch (HttpResponseException e)
{
Console.WriteLine(e.Message);
return 2;
}
bool logout = sdk.Logout();
if (!logout)
{
Console.WriteLine("Logout failed");
return 1;
}
return 0;
}
}
}
Set the required environment variables and run the code using dotnet run
.
$ export AB_BASE_URL="https://demo.accelbyte.io" # AccelByte Cloud Base URL e.g. demo environment
$ export AB_CLIENT_ID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # AccelByte Cloud OAuth Client ID
$ export AB_CLIENT_SECRET="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # AccelByte Cloud OAuth Client Secret
$ cd /path/to/mysolution/myproject
$ dotnet run
See our .NET (C#) SDK example repo (opens new window) for a selection of test cases you can use to customize your game. You can also view the .NET (C#) Server SDK README.md (opens new window) for more information.
SDK reference (opens new window)
using AccelByte.Sdk.Api.Iam.Model;
using AccelByte.Sdk.Api.Iam.Operation;
using AccelByte.Sdk.Api.Iam.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Basic.Model;
using AccelByte.Sdk.Api.Basic.Operation;
using AccelByte.Sdk.Api.Basic.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Social.Model;
using AccelByte.Sdk.Api.Social.Operation;
using AccelByte.Sdk.Api.Social.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Platform.Model;
using AccelByte.Sdk.Api.Platform.Operation;
using AccelByte.Sdk.Api.Platform.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Group.Model;
using AccelByte.Sdk.Api.Group.Operation;
using AccelByte.Sdk.Api.Group.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Cloudsave.Model;
using AccelByte.Sdk.Api.Cloudsave.Operation;
using AccelByte.Sdk.Api.Cloudsave.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Dsmc.Model;
using AccelByte.Sdk.Api.Dsmc.Operation;
using AccelByte.Sdk.Api.Dsmc.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Sessionbrowser.Model;
using AccelByte.Sdk.Api.Sessionbrowser.Operation;
using AccelByte.Sdk.Api.Sessionbrowser.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Lobby.Model;
using AccelByte.Sdk.Api.Lobby.Operation;
using AccelByte.Sdk.Api.Lobby.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Achievement.Model;
using AccelByte.Sdk.Api.Achievement.Operation;
using AccelByte.Sdk.Api.Achievement.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Dslogmanager.Model;
using AccelByte.Sdk.Api.Dslogmanager.Operation;
using AccelByte.Sdk.Api.Dslogmanager.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Ugc.Model;
using AccelByte.Sdk.Api.Ugc.Operation;
using AccelByte.Sdk.Api.Ugc.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Leaderboard.Model;
using AccelByte.Sdk.Api.Leaderboard.Operation;
using AccelByte.Sdk.Api.Leaderboard.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Gdpr.Model;
using AccelByte.Sdk.Api.Gdpr.Operation;
using AccelByte.Sdk.Api.Gdpr.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Legal.Model;
using AccelByte.Sdk.Api.Legal.Operation;
using AccelByte.Sdk.Api.Legal.Wrapper;
SDK reference (opens new window)
using AccelByte.Sdk.Api.Matchmaking.Model;
using AccelByte.Sdk.Api.Matchmaking.Operation;
using AccelByte.Sdk.Api.Matchmaking.Wrapper;