با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
گزینه دیگر برای ایجاد اعتبارنامه OAuth2 استفاده از OAuth2 Playground است. OAuth2 Playground، در ارتباط با Google API Console، به شما اجازه می دهد تا به صورت دستی توکن های OAuth2 را ایجاد کنید.
پیش نیازها
قبل از ایجاد اعتبارنامه، باید یک پروژه ایجاد کنید ، صفحه رضایت کاربر خود را پیکربندی کنید و AdMob API را فعال کنید.
از منوی کشویی پروژه، همان پروژه مورد استفاده برای تولید اعتبار را انتخاب کنید.
صفحه رضایت OAuth خود را برای استفاده از شناسه مشتری OAuth 2.0 پیکربندی کنید. راه های متعددی برای این کار وجود دارد:
نوع کاربری خود را روی خارجی و وضعیت انتشار را روی Published تنظیم کنید.
یا، نوع کاربری خود را روی External و وضعیت انتشار را روی Testing تنظیم کنید، سپس با انتخاب add users، کاربران آزمایشی را اضافه کنید تا به آنها دسترسی داشته باشید تا از شناسه مشتری OAuth 2.0 خود استفاده کنند.
به زمین بازی OAuth2 بروید، (با استفاده از این پیوند باید برخی از مقادیر کلیدی را از قبل برای شما پر کند).
روی نماد چرخ دنده کلیک کنید در گوشه سمت راست بالا و کادر با عنوان Use your own OAuth credentials را علامت بزنید (اگر قبلاً علامت زده نشده باشد).
اطمینان حاصل کنید که:
جریان OAuth روی سمت سرور تنظیم شده است.
نوع دسترسی روی آفلاین تنظیم شده است (این تضمین می کند که به جای یک نشانه دسترسی، یک نشانه تازه سازی و یک نشانه دسترسی دریافت می کنید).
شناسه مشتری OAuth2 و راز سرویس گیرنده OAuth2 را که در بالا به دست آورده اید وارد کنید.
در بخش با عنوان مرحله 1 - انتخاب و مجوز APIها ، URL زیر را در کادر متنی در پایین وارد کنید، اگر قبلاً وجود ندارد، سپس روی تأیید APIها کلیک کنید:
https://www.googleapis.com/auth/admob.readonly
در صورت درخواست، وارد حسابی شوید که میخواهید به آن دسترسی و مجوز بدهید. در غیر این صورت، تأیید کنید که کاربر فعلی Google در گوشه سمت راست بالا، حساب AdMob است که میخواهید اعتبارنامهای را برای او دریافت کنید.
درخواستی ظاهر میشود که نشان میدهد برنامه شما میخواهد دادههای AdMob شما را ببیند . برای ادامه روی Accept کلیک کنید.
در برگه با برچسب مرحله 2 - کد مجوز مبادله برای توکن ها ، یک کد مجوز باید ظاهر شود. روی کد مجوز تبادل برای توکنها کلیک کنید.
اگر همه چیز خوب پیش برود، رمز Refresh و نشانه دسترسی باید برای شما پر شود (شاید مجبور شوید مرحله 2 - کد مجوز تبادل برای توکن ها را دوباره گسترش دهید):
کد Refresh را به همراه شناسه مشتری و راز سرویس گیرنده در فایل پیکربندی کتابخانه مشتری انتخابی خود کپی کنید.
اکنون که یک نشانه بهروزرسانی دارید، دیگر نیازی به OAuth2 Playground ندارید تا یک URI تغییر مسیر مجاز باشد. برای حذف آن از لیست URI های مجاز تغییر مسیر:
در صفحه اعتبار، روی نام شناسه مشتری برای ویرایش کلیک کنید.
https://developers.google.com/oauthplayground از URIهای مجاز تغییر مسیر حذف کنید. توجه داشته باشید که باید حداقل یک URI تغییر مسیر را در محل خود بگذارید.
روی ذخیره کلیک کنید.
ابطال توکن های مشترک
شما می توانید توکن های مشترک را به دو روش لغو کنید:
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eOAuth2 Playground can be used to manually create OAuth2 tokens for accessing the AdMob API.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize OAuth2 Playground, you need to generate a client ID for a web application in the Google API Console.\u003c/p\u003e\n"],["\u003cp\u003eAn OAuth consent screen needs to be configured for the client ID, requiring setting the user type to External and the publishing status to either Published or Testing with added test users.\u003c/p\u003e\n"],["\u003cp\u003eAfter authorization, the OAuth2 Playground provides an access token and a refresh token; the refresh token, along with the client ID and client secret, should be saved for using the AdMob API client libraries.\u003c/p\u003e\n"],["\u003cp\u003eRemember to remove the OAuth2 Playground from the authorized redirect URIs in the Google API Console after obtaining the refresh token.\u003c/p\u003e\n"]]],["To generate OAuth2 credentials, use the OAuth2 Playground with the Google API Console. First, create a project, configure the user consent screen, and enable the AdMob API. Next, generate a client ID and secret for a web application, adding `https://developers.google.com/oauthplayground` as an authorized redirect URI. Configure an OAuth consent screen. Then, in the OAuth2 Playground, authorize the AdMob API, exchange the authorization code for tokens, and copy the refresh token, client ID, and client secret into your client library's configuration. Remove the OAuth2 playground from the authorized redirect URIs.\n"],null,["# OAuth Playground\n\nAnother option for generating OAuth2 credentials is to use the **OAuth2\nPlayground**. The OAuth2 Playground, in conjunction with the Google API Console,\nallows you to manually create OAuth2 tokens.\n\nPrerequisites\n-------------\n\nBefore creating credentials, you need to\n[create a project](/admob/api/v1/getting-started#create_project), configure your\nuser consent screen, and enable the AdMob API.\n\nGet a client ID and client secret\n---------------------------------\n\n### Create a credential\n\n| **Key Point:** To use the **OAuth2 Playground** , you need to generate a **client\n| ID** for a [web application](/identity/protocols/OAuth2WebServer). This is the *only* type of application that will work with the OAuth2 Playground.\n\n1. Open the [Google API Console\n Credentials page](https://console.cloud.google.com/apis/credentials).\n\n2. From the project drop-down, select an existing project or create a new one.\n\n | **Key Point:** Create a project with a unique identifying name for each shared token, so you can share or [revoke](/admob/api/v1/how-tos/playground#revoke_token) them easily.\n3. On the Credentials page, select **Create credentials** , then select\n **OAuth client ID**.\n\n4. Under **Application type** , choose **Web application**.\n\n5. Under **Authorized redirect URIs** , add a line with:\n `https://developers.google.com/oauthplayground`\n\n | **Key Point:** If you have an existing credential, you can reuse it by setting the Authorized redirect URIs as above.\n6. Click **Create**.\n\n7. On the Client ID page, take note of the **client ID** and **client secret**.\n You'll need these in the next step.\n\n### Configure an OAuth consent screen\n\nYou must configure an OAuth consent screen before using an OAuth 2.0 client ID.\n\n1. Open the [Google API Console\n Consent Screen page](https://console.cloud.google.com/apis/credentials/consent).\n\n2. From the project drop-down, select the same project used to generate the\n credential.\n\n3. Configure your OAuth consent screen to use your OAuth 2.0 client ID. There\n are multiple ways to do this:\n\n 1. Set your user type to **External** and publishing status to **Published**.\n 2. Or, set your user type to **External** and publishing status to **Testing** , then add **Test users** by selecting **add users** to give them access to use your OAuth 2.0 client ID.\n\nSee additional information on [setting up your OAuth consent screen](//support.google.com/cloud/answer/10311615).\n\nGenerate tokens\n---------------\n\n| **Key Point:** The Google user you're signed in as in your browser determines which AdMob account you'll be able to access with the OAuth2 credentials you generate. Therefore, you may want to do these steps in an incognito window or when you're not signed in to your Google account, since it's likely that the user whose credentials you want to use isn't the same user you were signed in as when you got the client ID and secret.\n\n1. Go to the [OAuth2\n Playground](/oauthplayground#step1&scopes=https%3A//www.googleapis.com/auth/admob.readonly&url=https%3A//&content_type=application/json&http_method=GET&useDefaultOauthCred=checked&oauthEndpointSelect=Google&oauthAuthEndpointValue=https%3A//accounts.google.com/o/oauth2/v2/auth&oauthTokenEndpointValue=https%3A//oauth2.googleapis.com/token&includeCredentials=unchecked&accessTokenType=bearer&autoRefreshToken=unchecked&accessType=offline&forceAprovalPrompt=checked&response_type=code),\n (using this link should pre-populate some key values for you).\n\n2. Click the gear icon\n in the upper right corner and check the box labeled **Use your own OAuth\n credentials** (if it isn't already checked).\n\n3. Make sure that:\n\n - **OAuth flow** is set to **Server-side**.\n - **Access type** is set to **Offline** (this ensures you get a refresh token *and* an access token, instead of just an access token).\n4. Enter the **OAuth2 client ID** and **OAuth2 client secret** you obtained\n above.\n\n5. In the section labeled **Step 1 - Select \\& authorize APIs** , enter the\n following URL in the text box at the bottom, if it's not already there,\n then click **Authorize APIs**:\n\n\n `https://www.googleapis.com/auth/admob.readonly`\n6. If prompted, sign in to the account to which you want to grant access and\n authorization. Otherwise, confirm that the current Google user in the top\n right corner is the AdMob account for whom you want to obtain credentials.\n\n | **Key Point:** If you got your client ID and secret only a few minutes ago, and you get an error such as `Error: redirect_uri_mismatch`, it's possible the changes you made haven't yet propagated. Click your browser's back button, wait a few minutes, then try clicking **Authorize APIs** again.\n7. A prompt appears indicating your app would like to **See your AdMob data** .\n Click **Accept** to continue.\n\n8. In the tab labeled **Step 2 - Exchange authorization code for tokens** ,\n an **Authorization code** should appear. Click **Exchange authorization\n code for tokens**.\n\n9. If all goes well, the **Refresh token** and **Access token** should be\n filled in for you (you may have to re-expand **Step 2 - Exchange\n authorization code for tokens**):\n\n10. Copy the **Refresh token** into the configuration file for your client\n library of choice, along with the **client ID** and **client secret**.\n\n11. [Configure a client library for OAuth in the\n AdMob API](/admob/api/v1/libraries).\n\nRemove the OAuth2 Playground from your client ID\n------------------------------------------------\n\nNow that you have a **refresh token**, you no longer need the OAuth2 Playground\nto be an authorized redirect URI. To remove it from the list of authorized\nredirect URIs:\n\n1. Go to the [Google API Console\n Credentials page](https://console.cloud.google.com/apis/credentials).\n\n2. From the project drop-down, select your project.\n\n3. On the Credentials page, click the **client ID name** to edit.\n\n4. Remove `https://developers.google.com/oauthplayground` from the **Authorized\n redirect URIs** . Note that you must leave at least *one* redirect URI in\n place.\n\n5. Click **Save**.\n\nRevoke shared tokens\n--------------------\n\nYou can revoke shared tokens in two ways:\n\n1. Navigate to your [Google account\n permissions](//myaccount.google.com/permissions) page and revoke access from\n the relevant project.\n\n2. Alternatively, you can revoke web application tokens using the [Google\n Identity API](/identity/protocols/oauth2/web-server#tokenrevoke)."]]