Snapchat をアイデンティティプロバイダーとして設定する
注釈:本資料はAI技術を用いて翻訳されています。
概要
このガイドは、認証されたSnapchatデベロッパーがSnapchatアカウントをAccelByte Gaming Services (AGS) に接続するのを支援することを目的としています。ここに記載されていないSnapchatサービス内の追加機能を設定する必要がある場合があります。Snapchatサービスの設定に関する完全な情報については、Snapchatの担当者に連絡し、Snapchatドキュメントを直接確認することをお勧めします。
このガイドは公開用であり、機密性のため限定的な情報が含まれています。まず完全な機密ガイドを参照することをお勧めします。機密ガイドのコピーをリクエストするには、AccelByteテクニカルプロデューサーにお問い合わせください。
目標
AccelByte Game SDKを使用してゲームのSnapchat認証方法を有効にします。
前提条件
- Snapchat Developerアカウント。
- Developer Accountの下の組織
- Unreal Engineを使用する場合は、UEバージョン4.27または5.0をインストールします。
- 認証を設定し、権限を管理するためのAccelByte Admin Portalアカウント。
- Player PortalとLauncher用のPublisher Namespace、およびゲーム用のGame Namespace。
- Player Portal。
- 最新バージョンのAccelByte Game SDKがインポートされたUnityまたはUnrealゲームプロジェクト。
- AGS Identity and Access Management (IAM) Clientsに関する知識。
Snapchat Kit Appの設定
Snap Kit Appの作成
Snapchat Developer Accountの下にSnap Kit Appを作成します。Snapchat's guide on Setting up your first app guideに従ってください。
Snap Login Kitのアクティベート
Snap Kit Appの下でSnap Login Kitをアクティベートし、OAuthのRedirect URIにドメインURL(例: https://prod.gamingservices.accelbyte.io)を入力します。詳細については、Snapchat's documentation on Login Kitを参照してください。
Snapchat用のゲーム内ログインの設定
これらの手順に従って、ゲームでSnapchatログインを設定します。これにより、プレイヤーはSnapchatアカウントを使用してゲームにサインインできるようになります。
-
AGS Admin portalで、パブリッシャーnamespaceに移動します。
-
サイドバーメニューで、Game Setup > 3rd Party Configuration > Auth & Account Linkingに移動します。
-
Login Methodsページで、+ Add Newボタンをクリックします。

-
ログイン方法オプションのリストから、Snapchatを選択します。

-
Client IDにSnap Kit Client IDを、Client SecretにSnap Kit Client Secretを、Redirect URIにSnapchat Login Kit OAuth Redirect URIを入力します。

-
詳細ページにリダイレクトされます。この時点でアクティベートするだけで使用できるようになります。

IAM Clientの作成
IAMクライアントは、ターゲットプラットフォームでリリースするゲームクライアントの表現です。
特定のSDKプラットフォーム(Xbox、Steam、Playstationなど)のゲーム用のIAM Clientをすでに持っている場合は、新しいIAM Clientを作成する必要はありません。Snapchatはゲームを構築するプラットフォームではないため、既存のIAM Clientを使用できます。IAM Clientsの詳細については、Manage access control for applicationsを参照してください。
ゲーム内ログイン手順
各ゲームエンジンの設定は異なります。利用可能なタブからゲームエンジンを選択してください。
- Unreal Engine Instructions
- Unity Instructions
Unrealゲーム内ログイン統合
AccelByte SDKを使用してSnapchat Gameをサインインに統合し、プレイヤーがSnapchat認証情報を使用してゲームにログインできるようにすることができます。
Unreal準備と設定
SnapchatはUE4の統合をサポートしていません。そのため、実装ではウェブログインを使用し、SnapChat AuthからログインコードをトークンとしてAccelByteにログインします。Snapchatアカウントは、デフォルトでヘッドレスアカウントとなるAccelByteアカウントにもリンクされます。
参照: https://docs.snap.com/snap-kit/login-kit/Tutorials/web
依存関係の追加
まず、AccelbyteUe4Sdkという公開依存関係モジュールを追加する必要があります。この依存関係は、Unreal Engine内でAccelByte SDKプラグインを使用するためにプロジェクトを統合するために必要です。
public ABThirdPartyLogin(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" , "AccelByteUe4Sdk", "Slate", "SlateCore" });
PrivateDependencyModuleNames.AddRange(new string[] { "Json", "HTTP" });
}
<YourProject>.Target.csと<YourProjectEditor>.Target.cs内にAccelbyteUe4Sdkを追加します
public ABThirdPartyLoginTarget( TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.AddRange( new string[] { "ABThirdPartyLogin", "AccelByteUe4Sdk" } );
}
public ABThirdPartyLoginEditorTarget( TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.AddRange( new string[] { "ABThirdPartyLogin", "AccelByteUe4Sdk" } );
}
Snapchat用のUnreal Engineプロジェクト設定
DefaultEngine.iniファイル内に、DefaultEngine.iniにAccelbyte認証情報を追加してください
[/Script/AccelByteUe4Sdk.AccelByteSettings]
ClientId=<Your Client_Id>
ClientSecret=<Your Client_Secret>
Namespace=<Your Namespace>
PublisherNamespace=<Your Publisher Namespace>
RedirectURI="http://127.0.0.1"
BaseUrl="https://prod.gamingservices.accelbyte.io"
IamServerUrl="https://prod.gamingservices.accelbyte.io/iam"
PlatformServerUrl="https://prod.gamingservices.accelbyte.io/platform"
[SnapChatConfig]
SnapChatClientId=<SnapChatClientId>
Unrealサンプルコード実装
次のステップでは、以下のサンプルコードを使用してゲームのSnapchat認証方法を実装する方法を示します。
-
BluePrintでWebBrowserアイテムをログインコンテナとして作成します。
-
Login Snapchat URLをロードします: https://accounts.snapchat.com/accounts/oauth2/auth
そして認証パラメータを追加します:
- redirect_uri: ログインが完了したときのRedirectURL。リダイレクトはゲームに戻るため、BaseURL(ApiClient->Settings->BaseUrl)で値を入力します。また、Snapchat開発者ポータルのRedirect Uri設定にBaseUrl値を入れてホワイトリストに登録します。
- response_type: 値を**"code"**にします。
- scope: 権限スコープで値を入れます \
| https://auth.snapchat.com/oauth2/api/user.display_name | ユーザーのSnapchat表示名へのアクセスを許可 |
| https://auth.snapchat.com/oauth2/api/user.bitmoji.avatar | ユーザーのBitmojiアバターへのアクセスを許可(ユーザーが切り替え可能) |
| https://auth.snapchat.com/oauth2/api/user.external_id | アプリケーションにユーザーをオンボードするために使用できるユーザーの外部IDへのアクセスを許可 |
スニペットで使用されるAccelByteOnlineSubsystemPtrを取得するには、このガイドに従ってください。
auto ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient(TEXT("YOUR_KEY"));
auto UserApi = ApiClient->GetUserApi().Pin();
void UAccelByteAuth::SnapChatLogin()
{
FString SnapChatClientId;
GConfig->GetString(TEXT("SnapChatConfig"), TEXT("SnapChatClientId"), SnapChatClientId, GEngineIni);
FString RedirectUri = ApiClient->Settings->BaseUrl;
FString Scope = TEXT("https://auth.snapchat.com/oauth2/api/user.display_name https://auth.snapchat.com/oauth2/api/user.bitmoji.avatar https://auth.snapchat.com/oauth2/api/user.external_id");
FString Url = FString::Printf(TEXT("https://accounts.snapchat.com/accounts/oauth2/auth?client_id=%s&redirect_uri=%s&response_type=%s&scope=%s"),
*FGenericPlatformHttp::UrlEncode(SnapChatClientId),
*FGenericPlatformHttp::UrlEncode(RedirectUri),
TEXT("code"),
*FGenericPlatformHttp::UrlEncode(Scope));
WBrowser_SnapChatAuth->LoadURL(Url);
WBrowser_SnapChatAuth->OnUrlChanged.AddUniqueDynamic(this, &UAccelByteAuth::AccelByteLoginWithSnapChat);
}
void UAccelByteAuth::AccelByteLoginWithSnapChat(const FText& NewUrl)
{
FString Url = NewUrl.ToString();
FString RedirectUri = ApiClient->Settings->BaseUrl;
FString LoginCode = TEXT("");
if (Url.Contains(RedirectUri))
{
LoginCode = FGenericPlatformHttp::GetUrlParameter(Url, TEXT("code")).GetValue();
}
if (!LoginCode.IsEmpty())
{
UserApi->LoginWithOtherPlatform(EAccelBytePlatformType::SnapChat, LoginCode, FVoidHandler::CreateWeakLambda(this, [this]()
{
// Handle Success Login
}),
FCustomErrorHandler::CreateWeakLambda(this, [](int32 ErrorCode, const FString& ErrorMessage, const FJsonObject& ErrorJson)
{
// Handle Error Login
}));
// Close Login Page (Hide WebBrowser)
}
}
platform_token(Snapchat認証用)はAuth Codeです
このサンプルコードをプロジェクトに追加した後、プロジェクトをコンパイル、ビルド、実行します。以上です!
サンプルコードのテスト
以下の画像は、Snapchatアカウントを使用してテストアプリに正常にログインした様子を示しています。

Unityゲーム内ログイン統合
AccelByte SDKを使用してSnapchatをサインインに統合し、プレイヤーがSnapchat認証情報を使用してゲームにログインできるようにすることができます。
Unity準備と設定
AccelByte Gaming Services用のUnityプロジェクト設定
AccelByte SDKがプロジェクトで適切に実行される前に、AccelByte Admin Portalで以前に作成した値を入力し、以下の各ステップに従う必要があります:
- Game Client設定用のファイルAccelByteSDKConfig.jsonを作成します。
- AccelByteSDKConfig.jsonファイルをコピーし、Assets/ResourceディレクトリのUnityプロジェクトディレクトリに追加します。
- ゲームに基づいた情報を使用してAccelByteSDKConfig.jsonファイルに入力します。以下はJSONファイルの例です:
{
"Default": {
"Namespace": "<Your Game Namespace>",
"UsePlayerPrefs": true,//It will use Player Preferences
"EnableDebugLog": true,//Enable Debug Logging
"DebugLogFilter": "Log",//Type of Debug Log
"BaseUrl": "https://prod.gamingservices.accelbyte.io",
"RedirectUri": "http://127.0.0.1",
"AppId": "<Your AppId>",
"PublisherNamespace": "<Your Publisher Namespace>"
}
}
- AccelByteServerSDKConfig.jsonというファイルを作成し、Assets/ResourceディレクトリのUnityプロジェクトディレクトリに追加します。
- Game Server設定として使用される以下のコードでAccelByteServerSDKConfig.jsonを更新します。以下はJSONファイルの例です:
{
"Default": {
"Namespace": "<Your Game Namespace>",
"BaseUrl": "https://prod.gamingservices.accelbyte.io",
"RedirectUri": "http://127.0.0.1"
}
}
- AccelByteSDKOAuthConfig.jsonとAccelByteServerSDKOAuthConfig.jsonという2つのファイルを作成します。これらのファイルの両方をAssets/ResourcesディレクトリのUnityプロジェクトディレクトリに追加します。これらのJSONファイルの両方の内容は次のようになります:
{
"Default": {
"ClientId": "<Your IAM Client ID>",
"ClientSecret": "<Your IAM Client Secret>"
}
}
Unityサンプルコード実装
次のステップでは、以下のサンプルコードを使用してゲームのSnapchat認証方法を実装する方法を示します。
snapchat apiを呼び出すためのカスタムsdkを作成する必要があります。以下は例です
[SerializeField] private string clientId = "Your Snapchat ClientId";
private string redirectUri = "http://127.0.0.1/";
[SerializeField] private string[] scopes =
{
"https://auth.snapchat.com/oauth2/api/user.display_name",
"https://auth.snapchat.com/oauth2/api/user.bitmoji.avatar",
"https://auth.snapchat.com/oauth2/api/user.external_id"
};
private const string authUrl = "https://accounts.snapchat.com/accounts/oauth2/auth";
private async void OnLoginClick()
{
SnapchatLoginButton.interactable = false;
LoginStatus.text = "Logging in...";
string scopeStr = string.Join("%20", scopes);
string url = $"{authUrl}?client_id={clientId}&redirect_uri=http://127.0.0.1&response_type=code&scope={scopeStr}";
// Open the URL in the default browser
Application.OpenURL(url);
// Wait for the authorization code
string authCode = await GetAuthorizationCode();
Debug.Log($"Snapchat auth code: {snapchatAuthCode}");
});
}
private async Task<string> GetAuthorizationCode()
{
string authCode = "";
bool receivedAuthCode = false;
// Wait for the user to complete the authentication process and receive the authorization code
float elapsedTime = 0;
float timeout = 10f; // Maximum time to wait for the user to complete the authentication process (in seconds)
while (!receivedAuthCode && elapsedTime < timeout)
{
authCode = await ListenForAuthorizationCode(redirectUri);
elapsedTime += 1f;
// Check if the authorization code has been received
if (!string.IsNullOrEmpty(snapchatAuthCode))
{
receivedAuthCode = true;
}
}
return authCode;
}
private async Task<string> ListenForAuthorizationCode(string redirectUri)
{
string authCode = "";
// Create a HttpListener instance to listen on the redirect URI
var listener = new HttpListener();
listener.Prefixes.Add(redirectUri);
listener.Start();
// Wait for a request to be received on the HttpListener
var context = await listener.GetContextAsync();
// Extract the authorization code from the request URI
var requestUri = context.Request.Url;
authCode = HttpUtility.ParseQueryString(requestUri.Query).Get("code");
// Send a response to the request with an HTML page that displays the authorization code
var response = context.Response;
var responseString = $"<html><body><h1>Authorization Code: {authCode}</h1></body></html>";
var buffer = Encoding.UTF8.GetBytes(responseString);
response.ContentLength64 = buffer.Length;
var output = response.OutputStream;
await output.WriteAsync(buffer, 0, buffer.Length);
// Close the HttpListener and return the authorization code
listener.Close();
return authCode;
}
This code below will handle LoginWithOtherPlatform which is the part of AccelByte SDK that handles third-party platform login by auth token obtained from the GetAuthSessionTicket method.
var apiClient = AccelByteSDK.GetClientRegistry().GetApi();
var user = apiClient.GetUser();
Result < TokenData, OAuthError > loginResult = null;
user.LoginWithOtherPlatform(PlatformType.Snapchat, snapAuthToken, (Result < TokenData, OAuthError > loginResult) => {
if (loginResult.IsError) {
//If we error, grab the Error Error and Description to print in the Log
Debug.Log($ "Login failed : {loginResult.Error.error} Description : {loginResult.Error.error_description}");
//Set the Status Text to display the Error if there is any
LoginStatus.text = $ "Login failed : {loginResult.Error.error} Description : {loginResult.Error.error_description}";
} else {
Debug.Log($ "Login successful : {loginResult.Value}");
LoginStatus.text = $ "Success Login Snapchat :{loginResult.Value.ToJsonString()}";
}
});
platform_token(Snapchat認証用)はAuth Codeです
Login Handlerスクリプトをプロジェクトに追加した後、プロジェクトをコンパイルできます。
サンプルコードのテスト
これで、プロジェクトをビルドして実行できます。以下の画像は、Snapchatアカウントを使用してテストアプリに正常にログインした様子を示しています。
