Google Play की गेम सेवाओं का इस्तेमाल करके, Unity में पुष्टि करें
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
Android गेम में खिलाड़ियों को साइन इन करने के लिए, Google Play की गेम सेवाओं का इस्तेमाल किया जा सकता है
इसे Firebase और Unity पर बनाया गया है. Google Play की गेम सेवाओं का इस्तेमाल करने के लिए, इनसे साइन इन करें
Firebase है, तो पहले Google Play Games से प्लेयर में साइन इन करें. इसके बाद,
OAuth 2.0 ऑथराइज़ेशन कोड. इसके बाद, ऑथराइज़ेशन कोड को पास करें
Firebase क्रेडेंशियल जनरेट करने के लिए PlayGamesAuthProvider, जिसका इस्तेमाल किया जा सकता है
Firebase की मदद से पुष्टि करें.
शुरू करने से पहले
अपना Unity प्रोजेक्ट सेट अप करें
अपने Unity प्रोजेक्ट में, Firebase कॉन्फ़िगरेशन फ़ाइल और FirebaseUnity SDK टूल जोड़ें
जैसा कि इसमें बताया गया है
Firebase को अपने Unity प्रोजेक्ट में जोड़ें.
Android के लिए निर्देशों का पालन करें.
FirebaseAuth.unitypackage को इंपोर्ट करना न भूलें.
Unity एडिटर में, बिल्ड सेटिंग > प्लेयर सेटिंग > किसी और तरीके से
सेटिंग से अपने गेम के Android पैकेज का नाम सेट करें.
इसके बाद, बिल्ड की सेटिंग > प्लेयर सेटिंग > पब्लिश करने की सेटिंग,
कोई कीस्टोर और कुंजी चुनें या बनाएं. इनका इस्तेमाल आपके Android डिवाइस पर साइन करने के लिए किया जाएगा
पैकेज. Play Games में साइन इन करने के लिए, आपके APK पर साइन किया जाना ज़रूरी है—यह
ये शर्तें सिर्फ़ पब्लिशिंग पर ही नहीं, बल्कि
आपका गेम.
अपना Firebase प्रोजेक्ट सेट अप करना
Firebase कंसोल में, Firebase प्रोजेक्ट पर जाएं
जिसमें आपने अपना Unity प्रोजेक्ट रजिस्टर किया है.
अपने गेम का SHA-1 फ़िंगरप्रिंट
सेटिंग पेज
Firebase कंसोल की, Unity में सेट की गई कुंजी का इस्तेमाल करके.
आपको keytool निर्देश का इस्तेमाल करके, अपनी कुंजी का SHA-1 फ़िंगरप्रिंट मिल सकता है:
अपने प्रोजेक्ट का वेब सर्वर क्लाइंट आईडी और क्लाइंट जनरेट करें और पाएं
सीक्रेट:
साइन इन करने का तरीका टैब में जाकर, Google में साइन इन करने की सुविधा चालू करें
कंपनी.
Google साइन इन से वेब सर्वर क्लाइंट आईडी और सीक्रेट को कॉपी करें
कंपनी.
साइन इन करने का तरीका टैब में, Play Games को चालू करें
साइन-इन करने वाली कंपनी को चुनें, और अपने प्रोजेक्ट के वेब सर्वर क्लाइंट आईडी को दर्ज करें और
की है, जो आपको आखिरी चरण में मिली थी.
Play Games services को अपने Firebase ऐप्लिकेशन की जानकारी के साथ कॉन्फ़िगर करें
इस
Google Play कंसोल,
अपना Google Play ऐप्लिकेशन खोलें या नया ऐप्लिकेशन बनाएं.
बढ़ाएं सेक्शन में,
Play Games services > सेटअप और मैनेजमेंट > कॉन्फ़िगरेशन.
हां, मेरे गेम में पहले से ही Google API का इस्तेमाल हो रहा है पर क्लिक करें. इसके बाद, अपना Firebase चुनें
प्रोजेक्ट चुनें और फिर इस्तेमाल करें पर क्लिक करें.
Play Games services कॉन्फ़िगरेशन पेज पर, क्लिक करें
क्रेडेंशियल जोड़ें.
गेम सर्वर टाइप चुनें.
OAuth क्लाइंट फ़ील्ड में, अपने प्रोजेक्ट का वेब क्लाइंट आईडी चुनें. होना
पक्का करें कि यह वही क्लाइंट आईडी है जिसे आपने चालू करते समय तय किया था
Play Games साइन इन.
बदलावों को सेव करें.
अब भी Play Games services कॉन्फ़िगरेशन पेज पर, क्लिक करें
फिर से क्रेडेंशियल जोड़ें.
Android टाइप चुनें.
OAuth क्लाइंट फ़ील्ड में, अपने प्रोजेक्ट का Android क्लाइंट आईडी चुनें.
(अगर आपको अपना Android क्लाइंट आईडी नहीं दिखता है, तो अपने गेम के
Firebase कंसोल में SHA-1 फ़िंगरप्रिंट.)
बदलावों को सेव करें.
इवेंट, उपलब्धियां, और लीडरबोर्ड पेजों पर, किसी भी इवेंट के लिए,
Play Games संसाधन जिन्हें आपको अपने गेम के साथ इस्तेमाल करना है (अगर आपको ये संसाधन नहीं चाहिए
तो किसी प्लेसहोल्डर एंट्री का तुरंत इस्तेमाल करने के लिए, प्लेसहोल्डर एंट्री बनाई जा सकती है). इसके बाद,
किसी भी इवेंट, उपलब्धियां या लीडरबोर्ड पेज पर,
संसाधन पाएं और Android संसाधन स्निपेट को कहीं भी कॉपी करें
सुविधाजनक. Google Play Games services को सेट अप करने के लिए, आपको स्निपेट की ज़रूरत होगी
प्लग इन.
प्लगिन के Unity पैकेज को अपने Unity प्रोजेक्ट में इंपोर्ट करें. आप
रिलीज़ संग्रह की current-build डायरेक्ट्री में Unity पैकेज.
Play Games प्लगिन को सेट अप करें:
विंडो > पर क्लिक करें Google Play Games > सेटअप > Android सेटअप:
Android कॉन्फ़िगरेशन स्क्रीन.
Play Console से मिले 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();
इसके बाद, जब कोई खिलाड़ी Play Games से साइन इन करने का विकल्प चुनता है, तो
Social.localUser.Authenticate():
Social.localUser.Authenticate((boolsuccess)=>{// handle success or failure});
Firebase की मदद से पुष्टि करें
अपने गेम में Play Games में साइन इन करने को जोड़ने के बाद, आप इससे मिले ऑथराइज़ेशन कोड का इस्तेमाल कर सकते हैं
Play Games की सेवाओं को Firebase की मदद से पुष्टि करनी होगी.
Play Games का इस्तेमाल करके खिलाड़ी के साइन इन करने के बाद, साइन इन करें
जारी रखने के हैंडलर में, प्लेयर के खाते के लिए पुष्टि करने का कोड पाएं:
इसके बाद, Play की गेम सेवाओं से मिले ऑथराइज़ेशन कोड को Firebase के लिए बदलें
क्रेडेंशियल पर जाएं और प्लेयर की पुष्टि करने के लिए 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 यूआईडी
Firebase.Auth.FirebaseUser ऑब्जेक्ट:
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;}
अपने Firebase रीयल टाइम डेटाबेस और Cloud Storage के सुरक्षा नियमों में, आपको ये चीज़ें मिल सकती हैं
auth वैरिएबल से साइन-इन किए हुए उपयोगकर्ता का यूनीक यूज़र आईडी. साथ ही, इसका इस्तेमाल इन कामों के लिए करें
तय करें कि उपयोगकर्ता कौनसा डेटा ऐक्सेस कर सकता है.
उपयोगकर्ता के Play Games खिलाड़ी की जानकारी पाने या Play Games की सेवाएं ऐक्सेस करने के लिए,
Play Games प्लगिन से मिले एपीआई का इस्तेमाल करें.
किसी उपयोगकर्ता को साइन आउट करने के लिए, SignOut() पर कॉल करें:
[null,null,["आखिरी बार 2025-08-16 (UTC) को अपडेट किया गया."],[],[],null,["# Authenticate in Unity Using Google Play Games Services\n\nYou 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----------------\n\n### Set 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\n### Set 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\n### Configure 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-------------------------------------------\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--------------------------\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----------\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();"]]