Google Play গেম পরিষেবাগুলি ব্যবহার করে ইউনিটিতে প্রমাণীকরণ করুন৷
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
আপনি ফায়ারবেস এবং ইউনিটিতে তৈরি একটি অ্যান্ড্রয়েড গেমে খেলোয়াড়দের সাইন ইন করতে Google Play গেম পরিষেবাগুলি ব্যবহার করতে পারেন৷ Google Play Games পরিষেবাগুলি ব্যবহার করতে Firebase-এর সাথে সাইন-ইন করুন, প্রথমে Google Play Games-এর মাধ্যমে প্লেয়ারে সাইন-ইন করুন এবং যখন আপনি তা করবেন তখন একটি OAuth 2.0 auth কোডের অনুরোধ করুন৷ তারপর, একটি Firebase শংসাপত্র তৈরি করতে PlayGamesAuthProvider এ অনুমোদন কোডটি পাস করুন, যা আপনি Firebase-এর সাথে প্রমাণীকরণ করতে ব্যবহার করতে পারেন।
আপনি শুরু করার আগে
আপনার ইউনিটি প্রকল্প সেট আপ করুন
আপনার ইউনিটি প্রোজেক্টে Firebase কনফিগারেশন ফাইল এবং FirebaseUnity SDK যোগ করুন যেমন Firebase যোগ করুন আপনার ইউনিটি প্রোজেক্টে বর্ণনা করা হয়েছে। অ্যান্ড্রয়েডের জন্য নির্দেশাবলী অনুসরণ করুন।
FirebaseAuth.unitypackage আমদানি করতে ভুলবেন না।
ইউনিটি এডিটরে, বিল্ড সেটিংস > প্লেয়ার সেটিংস > অন্যান্য সেটিংসের অধীনে আপনার গেমের অ্যান্ড্রয়েড প্যাকেজের নাম সেট করুন।
তারপরে, বিল্ড সেটিংস > প্লেয়ার সেটিংস > প্রকাশনা সেটিংসের অধীনে, একটি কীস্টোর এবং কী নির্বাচন করুন বা তৈরি করুন, যা আপনার অ্যান্ড্রয়েড প্যাকেজ স্বাক্ষর করতে ব্যবহার করা হবে। আপনার APK অবশ্যই Play Games সাইন-ইন করার জন্য সাইন ইন করতে হবে—এই প্রয়োজনীয়তা শুধুমাত্র প্রকাশের জন্য নয়, আপনার গেমের বিকাশের সময়ও প্রযোজ্য।
আপনার Firebase প্রকল্প সেট আপ করুন
Firebase কনসোলে , Firebase প্রজেক্টে যান যেখানে আপনি আপনার ইউনিটি প্রজেক্ট নিবন্ধন করেছেন।
ইউনিটিতে আপনার সেট করা কী ব্যবহার করে Firebase কনসোলের সেটিংস পৃষ্ঠা থেকে আপনার গেমের SHA-1 ফিঙ্গারপ্রিন্ট সেট করুন।
আপনি keytool কমান্ডের সাহায্যে আপনার কীটির SHA-1 ফিঙ্গারপ্রিন্ট পেতে পারেন:
আপনার প্রজেক্টের ওয়েব সার্ভার ক্লায়েন্ট আইডি এবং ক্লায়েন্ট সিক্রেট তৈরি করুন এবং প্রাপ্ত করুন:
সাইন ইন পদ্ধতি ট্যাবের মধ্যে, Google সাইন-ইন প্রদানকারী সক্ষম করুন৷
ওয়েব সার্ভার ক্লায়েন্ট আইডি এবং Google সাইন-ইন প্রদানকারীর গোপনীয়তা অনুলিপি করুন।
সাইন ইন পদ্ধতি ট্যাবের মধ্যে, Play Games সাইন-ইন প্রদানকারী সক্ষম করুন এবং আপনার প্রকল্পের ওয়েব সার্ভার ক্লায়েন্ট আইডি এবং ক্লায়েন্ট সিক্রেট নির্দিষ্ট করুন, যা আপনি শেষ ধাপে পেয়েছেন।
আপনার Firebase অ্যাপের তথ্য দিয়ে Play Games services কনফিগার করুন
গ্রো বিভাগে, Play Games services > সেটআপ এবং পরিচালনা > কনফিগারেশন ক্লিক করুন।
হ্যাঁ ক্লিক করুন, আমার গেম ইতিমধ্যেই Google API ব্যবহার করছে , তালিকা থেকে আপনার ফায়ারবেস প্রকল্প নির্বাচন করুন এবং তারপর ব্যবহার করুন ক্লিক করুন।
Play Games services কনফিগারেশন পৃষ্ঠায়, শংসাপত্র যোগ করুন ক্লিক করুন।
গেম সার্ভারের ধরন নির্বাচন করুন।
OAuth ক্লায়েন্ট ক্ষেত্রে, আপনার প্রকল্পের ওয়েব ক্লায়েন্ট আইডি নির্বাচন করুন। নিশ্চিত করুন যে এটি সেই একই ক্লায়েন্ট আইডি যা আপনি Play Games সাইন-ইন সক্ষম করার সময় নির্দিষ্ট করেছেন৷
আপনার পরিবর্তন সংরক্ষণ করুন.
এখনও Play Games services কনফিগারেশন পৃষ্ঠায়, আবার শংসাপত্র যোগ করুন ক্লিক করুন৷
অ্যান্ড্রয়েড টাইপ নির্বাচন করুন।
OAuth ক্লায়েন্ট ক্ষেত্রে, আপনার প্রকল্পের Android ক্লায়েন্ট আইডি নির্বাচন করুন। (আপনি যদি আপনার অ্যান্ড্রয়েড ক্লায়েন্ট আইডি দেখতে না পান তবে নিশ্চিত হন যে আপনি Firebase কনসোলে আপনার গেমের SHA-1 ফিঙ্গারপ্রিন্ট সেট করেছেন।)
আপনার পরিবর্তন সংরক্ষণ করুন.
ইভেন্ট , অ্যাচিভমেন্টস এবং লিডারবোর্ড পৃষ্ঠাগুলিতে, আপনি আপনার গেমের সাথে ব্যবহার করতে চান এমন যেকোন Play Games সংস্থান তৈরি করুন (যদি আপনি অবিলম্বে ব্যবহার করতে না চান তবে আপনি একটি স্থানধারক এন্ট্রি তৈরি করতে পারেন)। তারপর, যেকোনো ইভেন্ট , অর্জন বা লিডারবোর্ড পৃষ্ঠাগুলিতে, রিসোর্স পান ক্লিক করুন এবং সুবিধাজনক জায়গায় Android রিসোর্স স্নিপেটটি অনুলিপি করুন। Google Play Games services প্লাগইন সেট আপ করার জন্য আপনার স্নিপেটের প্রয়োজন হবে।
আপনি Play কনসোল থেকে সম্পদ সংজ্ঞা ক্ষেত্রের মধ্যে Android সম্পদ স্নিপেট পেস্ট করুন.
আপনার ওয়েব সার্ভার ক্লায়েন্ট আইডি পেস্ট করুন, যা আপনি প্রদান করেছিলেন যখন আপনি Firebase কনসোলে Play Games সাইন-ইন সক্ষম করেছিলেন, ক্লায়েন্ট আইডি ক্ষেত্রে।
সেটআপ এ ক্লিক করুন।
আপনার গেমে, RequestServerAuthCode সেটিং সক্ষম করে একটি Play Games ক্লায়েন্ট কনফিগার করুন:
usingGooglePlayGames;usingGooglePlayGames.BasicApi;usingUnityEngine.SocialPlatforms;usingSystem.Threading.Tasks;PlayGamesClientConfigurationconfig=newPlayGamesClientConfiguration.Builder().RequestServerAuthCode(false/* Don't force refresh */).Build();PlayGamesPlatform.InitializeInstance(config);PlayGamesPlatform.Activate();
তারপর, যখন একজন খেলোয়াড় প্লে গেমের সাথে সাইন ইন করতে পছন্দ করে, তখন Social.localUser.Authenticate() কল করুন :
Social.localUser.Authenticate((boolsuccess)=>{// handle success or failure});
Firebase দিয়ে প্রমাণীকরণ করুন
আপনি আপনার গেমে প্লে গেমস সাইন-ইন যোগ করার পরে, আপনি Firebase এর সাথে প্রমাণীকরণ করতে Play Games পরিষেবাগুলি থেকে প্রমাণীকরণ কোড ব্যবহার করতে পারেন৷
প্লে গেমস ব্যবহার করে প্লেয়ার সফলভাবে সাইন ইন করার পরে, সাইন-ইন কন্টিনিউয়েশন হ্যান্ডলারে, প্লেয়ারের অ্যাকাউন্টের জন্য একটি প্রমাণীকরণ কোড পান:
তারপর, ফায়ারবেস শংসাপত্রের জন্য প্লে গেম পরিষেবাগুলি থেকে প্রমাণীকরণ কোড বিনিময় করুন এবং প্লেয়ারটিকে প্রমাণীকরণ করতে Firebase শংসাপত্র ব্যবহার করুন:
Firebase.Auth.FirebaseAuthauth=Firebase.Auth.FirebaseAuth.DefaultInstance;Firebase.Auth.Credentialcredential=Firebase.Auth.PlayGamesAuthProvider.GetCredential(authCode);auth.SignInAndRetrieveDataWithCredentialAsync(credential).ContinueWith(task=>{if(task.IsCanceled){Debug.LogError("SignInAndRetrieveDataWithCredentialAsync was canceled.");return;}if(task.IsFaulted){Debug.LogError("SignInAndRetrieveDataWithCredentialAsync encountered an error: "+task.Exception);return;}Firebase.Auth.AuthResultresult=task.Result;Debug.LogFormat("User signed in successfully: {0} ({1})",result.User.DisplayName,result.User.UserId);});
পরবর্তী পদক্ষেপ
একজন ব্যবহারকারী প্রথমবার সাইন ইন করার পরে, একটি নতুন ব্যবহারকারীর অ্যাকাউন্ট তৈরি করা হয় এবং তাদের প্লে গেম আইডির সাথে লিঙ্ক করা হয়। এই নতুন অ্যাকাউন্টটি আপনার Firebase প্রকল্পের অংশ হিসাবে সংরক্ষণ করা হয়েছে এবং আপনার প্রকল্পের প্রতিটি অ্যাপ জুড়ে একজন ব্যবহারকারীকে শনাক্ত করতে ব্যবহার করা যেতে পারে।
Firebase.Auth.FirebaseUseruser=auth.CurrentUser;if(user!=null && user.IsValid()){stringplayerName=user.DisplayName;// The user's Id, unique to the Firebase project.// Do NOT use this value to authenticate with your backend server, if you// have one; use User.TokenAsync() instead.stringuid=user.UserId;}
আপনার ফায়ারবেস রিয়েলটাইম ডেটাবেস এবং ক্লাউড স্টোরেজ সুরক্ষা নিয়মে, আপনি auth ভেরিয়েবল থেকে সাইন-ইন করা ব্যবহারকারীর অনন্য ব্যবহারকারী আইডি পেতে পারেন এবং ব্যবহারকারী কোন ডেটা অ্যাক্সেস করতে পারে তা নিয়ন্ত্রণ করতে এটি ব্যবহার করতে পারেন।
একজন ব্যবহারকারীর প্লে গেম প্লেয়ারের তথ্য পেতে বা প্লে গেম পরিষেবাগুলি অ্যাক্সেস করতে, প্লে গেম প্লাগইন দ্বারা প্রদত্ত API ব্যবহার করুন৷
একজন ব্যবহারকারীকে সাইন আউট করতে, SignOut() কল করুন :
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-09-04 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["You can use Google Play Games services to sign in players to an Android game\nbuilt on Firebase and Unity. To use Google Play Games services sign-in with\nFirebase, first sign in the player with Google Play Games, and request an\nOAuth 2.0 auth code when you do so. Then, pass the auth code to\n`PlayGamesAuthProvider` to generate a Firebase credential, which you can use to\nauthenticate with Firebase.\n| **Important:** You can use Google Play Games services sign-in only on Android.\n\nBefore you begin\n\nSet up your Unity project\n\n1. Add the Firebase config file and the Firebase Unity SDK to your Unity project\n as described in\n [Add Firebase to your Unity project](/docs/unity/setup#set_up_environment).\n Follow the instructions for Android.\n\n Be sure to import `FirebaseAuth.unitypackage`.\n2. In the Unity Editor, under **Build Settings \\\u003e Player Settings \\\u003e Other\n Settings** set the Android package name of your game.\n\n3. Then, under **Build Settings \\\u003e Player Settings \\\u003e Publishing Settings**,\n select or create a keystore and key, which will be used to sign your Android\n package. Your APK must be signed for Play Games sign-in to work---this\n requirement applies not just for publishing, but also during development of\n your game.\n\nSet up your Firebase project\n\n1. In the [Firebase console](//console.firebase.google.com/), go to the Firebase project\n in which you registered your Unity project.\n\n2. Set your game's SHA-1 fingerprint from the\n [Settings](//console.firebase.google.com/project/_/settings/general/) page\n of the Firebase console, using the key you set in Unity.\n\n You can get the SHA-1 fingerprint of your key with the `keytool` command: \n\n ```\n keytool -exportcert -list -v \\\n -alias YOUR-KEY-NAME -keystore PATH-TO-KEYSTORE\n ```\n\n \u003cbr /\u003e\n\n Alternatively, you can get the SHA hash of your signing certificate with the\n gradle `signingReport` command: \n\n ```\n gradlew signingReport\n ```\n\n \u003cbr /\u003e\n\n Your APK must be signed with this key, including during development.\n3. Enable Google Play Games as a sign-in provider:\n\n 1. In the Firebase console, open the\n [**Authentication** section](//console.firebase.google.com/project/_/authentication/providers).\n\n 2. Generate and obtain your project's web server client ID and client\n secret:\n\n 1. Within the **Sign in method** tab, enable the **Google** sign-in\n provider.\n\n 2. Copy the web server client ID and secret from the **Google** sign-in\n provider.\n\n 3. Within the **Sign in method** tab, enable the **Play Games**\n sign-in provider, and specify your project's web server client ID and\n client secret, which you got in the last step.\n\nConfigure Play Games services with your Firebase app information\n\n1. In the\n [Google Play Console](https://play.google.com/console/developers),\n open your Google Play app or create one.\n\n2. In the *Grow* section, click\n **Play Games services \\\u003e Setup \\& Management \\\u003e Configuration**.\n\n3. Click **Yes, my game already uses Google APIs** , select your Firebase\n project from the list, and then click **Use**.\n\n4. On the Play Games services configuration page, click\n **Add Credential**.\n\n 1. Select the **Game server** type.\n 2. In the **OAuth client** field, select your project's web client ID. Be sure this is the same client ID you specified when you enabled Play Games sign-in.\n 3. Save your changes.\n5. Still on the Play Games services configuration page, click\n **Add Credential** again.\n\n 1. Select the **Android** type.\n 2. In the **OAuth client** field, select your project's Android client ID. (If you don't see your Android client ID, be sure you set your game's SHA-1 fingerprint in the Firebase console.)\n 3. Save your changes.\n6. On the **Events** , **Achievements** , and **Leaderboards** pages, create any\n Play Games resources you want to use with your game (if you don't\n want to use any immediately, you can create a placeholder entry). Then, on\n any of the **Events** , **Achievements** , or **Leaderboards** pages, click\n **Get resources** and copy the Android resources snippet somewhere\n convenient. You will need the snippet to set up the Google Play Games services\n plugin.\n\n The resources snippet looks like the following example: \n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003c!--\n Google Play game services IDs.\n Save this file as res/values/games-ids.xml in your project.\n --\u003e\n \u003cresources\u003e\n \u003c!-- app_id --\u003e\n \u003cstring name=\"app_id\" translatable=\"false\"\u003e123456789000\u003c/string\u003e\n \u003c!-- package_name --\u003e\n \u003cstring name=\"package_name\" translatable=\"false\"\u003ecom.example.game\u003c/string\u003e\n \u003c!-- event Wiped Raid --\u003e\n \u003cstring name=\"event_wiped_raid\" translatable=\"false\"\u003eCgkIpKjv1a4PEAIYBA\u003c/string\u003e\n \u003c/resources\u003e\n\n7. On the **Testers** page, add the email addresses of any users who need\n to be able to sign in to your game before you release it on the\n Play Store.\n\nIntegrate Play Games sign-in into your game\n\n1. Download the latest release of the\n [Play Games plugin for Unity](https://github.com/playgameservices/play-games-plugin-for-unity/releases)\n and extract it.\n\n2. Import the plugin's Unity package into your Unity project. You can find the\n Unity package in the `current-build` directory of the release archive.\n\n3. Set up the Play Games plugin:\n\n 1. Click **Window \\\u003e Google Play Games \\\u003e Setup \\\u003e Android Setup** to open the **Android Configuration** screen.\n 2. Paste the Android resources snippet you got from the Play console into the **Resources Definition** field.\n 3. Paste your web server client ID, which you provided when you enabled Play Games sign-in in the Firebase console, into the **Client ID** field.\n 4. Click **Setup**.\n4. In your game, configure a Play Games client with the `RequestServerAuthCode`\n setting enabled:\n\n using GooglePlayGames;\n using GooglePlayGames.BasicApi;\n using UnityEngine.SocialPlatforms;\n using System.Threading.Tasks;\n\n PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()\n .RequestServerAuthCode(false /* Don't force refresh */)\n .Build();\n\n PlayGamesPlatform.InitializeInstance(config);\n PlayGamesPlatform.Activate();\n\n5. Then, when a player chooses to sign in with Play Games, call\n `Social.localUser.Authenticate()`:\n\n Social.localUser.Authenticate((bool success) =\u003e {\n // handle success or failure\n });\n\nAuthenticate with Firebase\n\nAfter you add Play Games sign-in to your game, you can use the auth code from\nPlay Games services to authenticate with Firebase.\n\n1. After the player has successfully signed in using Play Games, in the sign-in\n continuation handler, get an auth code for the player's account:\n\n Social.localUser.Authenticate((bool success) =\u003e {\n if (success) {\n authCode = PlayGamesPlatform.Instance.GetServerAuthCode();\n }\n });\n\n2. Then, exchange the auth code from Play Games services for a Firebase\n credential, and use the Firebase credential to authenticate the player:\n\n Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;\n Firebase.Auth.Credential credential =\n Firebase.Auth.PlayGamesAuthProvider.GetCredential(authCode);\n auth.SignInAndRetrieveDataWithCredentialAsync(credential).ContinueWith(task =\u003e {\n if (task.IsCanceled) {\n Debug.LogError(\"SignInAndRetrieveDataWithCredentialAsync was canceled.\");\n return;\n }\n if (task.IsFaulted) {\n Debug.LogError(\"SignInAndRetrieveDataWithCredentialAsync encountered an error: \" + task.Exception);\n return;\n }\n\n Firebase.Auth.AuthResult result = task.Result;\n Debug.LogFormat(\"User signed in successfully: {0} ({1})\",\n result.User.DisplayName, result.User.UserId);\n });\n\nNext steps\n\nAfter a user signs in for the first time, a new user account is created and\nlinked to their Play Games ID. This new account is stored as part of your\nFirebase project, and can be used to identify a user across every app in your\nproject.\n\nIn your game, you can get the user's Firebase UID from the\n`Firebase.Auth.FirebaseUser` object: \n\n Firebase.Auth.FirebaseUser user = auth.CurrentUser;\n if (user != null && user.IsValid()) {\n string playerName = user.DisplayName;\n\n // The user's Id, unique to the Firebase project.\n // Do NOT use this value to authenticate with your backend server, if you\n // have one; use User.TokenAsync() instead.\n string uid = user.UserId;\n }\n\nIn your Firebase Realtime Database and Cloud Storage Security Rules, you can get\nthe signed-in user's unique user ID from the `auth` variable, and use it to\ncontrol what data a user can access.\n\nTo get a user's Play Games player information or to access Play Games services,\nuse the APIs provided by the Play Games plugin.\n\nTo sign out a user, call `SignOut()`: \n\n auth.SignOut();"]]