हमारे प्रॉडक्ट के बारे में चर्चा करने और सुझाव देने के लिए, Google विज्ञापन और मेज़रमेंट कम्यूनिटी सर्वर में Google Ads के आधिकारिक Discord चैनल से जुड़ें.
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
इस गाइड में, अपने क्रेडेंशियल और डेस्कटॉप फ़्लो या वेब फ़्लो का इस्तेमाल करके, एपीआई को ऐक्सेस करने के लिए OAuth 2.0 को सेट अप करने का तरीका बताया गया है. यह तरीका सिर्फ़ एक बार अपनाना होगा. ऐसा तब तक करना होगा, जब तक कि आपको अपने OAuth 2.0 क्रेडेंशियल के लिए अनुमति वाले स्कोप को रद्द, मिटाना या बदलना न पड़े.
क्लाइंट आईडी और क्लाइंट सीक्रेट नोट करें. इसके बाद, इस पेज पर वापस आएं.
क्लाइंट लाइब्रेरी सेट अप करना
टर्मिनल में, GenerateUserCredentialsउदाहरण चलाएं. जब कहा जाए, तब OAuth 2.0 क्लाइंट आईडी और क्लाइंट सीक्रेट डालें.
dotnet run GenerateUserCredentials.csproj
इस कोड के उदाहरण से, ब्राउज़र में यूआरएल अपने-आप खुलता है. अगर आपने ब्राउज़र सेशन में साइन इन नहीं किया है, तो वेब पेज पर आपको अपने Google खाते में साइन इन करने के लिए कहा जाएगा. अगर आपने पहले से ही साइन इन किया हुआ है, तो यह साइन इन करने के अनुरोध को स्किप कर देगा और आपको एक यूआरएल पर रीडायरेक्ट कर देगा. यहां आपको ऐप्लिकेशन को अपनी ओर से Google Ads खाता ऐक्सेस करने की अनुमति देनी होगी.
उस Google खाते से साइन इन करें जिसका इस्तेमाल Google Ads को ऐक्सेस करने के लिए किया जाता है. आम तौर पर, यह किसी Google Ads मैनेजर खाते में लॉगिन करने के लिए ईमेल होता है. इसमें वे सभी खाते होते हैं जिन्हें आपको खाते की हैरारकी के तहत मैनेज करना होता है. OAuth 2.0 की सहमति वाली स्क्रीन पर, जारी रखें पर क्लिक करें.
आपको एक पेज पर ले जाया जाएगा. इस पेज पर, अनुमति मिलने का मैसेज दिखेगा.
Your refresh token has been fetched. Check the
console output for further instructions.
उस कंसोल पर वापस जाएं जहां कोड का उदाहरण चलाया जा रहा है. आपको दिखेगा कि कोड का उदाहरण पूरा हो गया है और आपका रीफ़्रेश टोकन और कुछ निर्देश दिख रहे हैं. इसके बाद, क्लाइंट लाइब्रेरी को कॉन्फ़िगर करने के लिए, आपको दिए गए निर्देशों का पालन करना होगा:
Copy the following content into your App.config file.
<add key = 'OAuth2Mode' value = 'APPLICATION' />
<add key = 'OAuth2ClientId' value = '******' />
<add key = 'OAuth2ClientSecret' value = '******' />
<add key = 'OAuth2RefreshToken' value = '******' />
पक्का करें कि आपने अपनी App.config
फ़ाइल में LOGIN_CUSTOMER_ID हेडर भी सेट किया हो. ज़्यादा जानने के लिए,
कॉन्फ़िगरेशन गाइड देखें.
<add key = 'LoginCustomerId' value = 'INSERT_LOGIN_CUSTOMER_ID_HERE' />
इंटरैक्टिव ऐप्लिकेशन के लिए OAuth2 क्रेडेंशियल जनरेट करना
अगर आपको एपीआई कॉल करने के लिए, पहले से Google Ads खाते की जानकारी नहीं है, तो रनटाइम के दौरान इसे पता लगाया जा सकता है. इसके लिए, सेशन के लिए साइन इन किए हुए उपयोगकर्ता के क्रेडेंशियल का इस्तेमाल करें. AuthenticateInAspNetCoreApplication में, ऐसे उदाहरण देखें जहां मौजूदा साइन इन उपयोगकर्ता की पुष्टि की गई है और रनटाइम के दौरान OAuth2 क्रेडेंशियल हासिल किए गए हैं.
[null,null,["आखिरी बार 2025-08-31 (UTC) को अपडेट किया गया."],[[["\u003cp\u003eStarting with version 19.0.0, the Google Ads API client library for .NET will no longer support .NET 5.0, requiring an upgrade before the end of 2024 for continued functionality.\u003c/p\u003e\n"],["\u003cp\u003eThis guide explains how to set up OAuth2 for API access using your own credentials, offering two methods: the desktop flow and the web flow.\u003c/p\u003e\n"],["\u003cp\u003eYou can simplify API calls by linking your Google Ads accounts under a single manager account and using the provided example to generate OAuth2 credentials.\u003c/p\u003e\n"],["\u003cp\u003eFor interactive applications where the Google Ads account is unknown beforehand, you can discover it at runtime using the credentials of the signed-in user, as demonstrated in the provided example.\u003c/p\u003e\n"]]],[],null,["# OAuth Desktop and Web Application Flows\n\nThis guide walks you through how to set up OAuth 2.0 for API access using your\nown credentials and either the [desktop flow](/identity/protocols/oauth2/native-app)\nor the [web flow](/identity/protocols/oauth2/web-server). These steps only need\nto be done once, unless you revoke, delete, or need to change the allowed scopes\nfor your OAuth 2.0 credentials.\n\nCreate OAuth 2.0 credentials\n----------------------------\n\n1. Follow the steps to [configure a Google API Console project for the\n Google Ads API](/google-ads/api/docs/oauth/cloud-project).\n\n2. Note the *client ID* and *client secret*, then come back to this page.\n\nSet up the client library\n-------------------------\n\n| The following steps run an interactive code example, which will require you to provide input.\n\n1. In a terminal, run the [`GenerateUserCredentials`](https://github.com/googleads/google-ads-dotnet/blob/main/Google.Ads.GoogleAds/examples/Authentication/GenerateUserCredentials)example. Enter the OAuth 2.0 client ID and client secret\n when prompted.\n\n ```\n dotnet run GenerateUserCredentials.csproj\n ```\n2. This code example opens a URL automatically in the browser. If you aren't signed in to your\n browser session, the web page will prompt you to sign in to your Google Account. If you are\n already signed in, it will skip the sign-in prompt and redirect you to a URL where you must\n authorize the app to access your Google Ads account on your behalf.\n\n Sign in with the Google Account you use to access Google Ads. Usually, this is a login\n email to a Google Ads manager account that contains all the accounts you need to manage\n under its account hierarchy. Click **Continue** on the OAuth 2.0 consent screen.\n\n You'll be taken to a page with a message indicating that the authorization\n succeeded. \n\n ```\n Your refresh token has been fetched. Check the\n console output for further instructions.\n ```\n3. Return to the console where you're running the code example. You'll see that the code\n example has completed and is displaying your refresh token and some instructions, followed by\n the instructions you'll need to follow to configure the client library:\n\n Copy the following content into your App.config file.\n\n \u003cadd key = 'OAuth2Mode' value = 'APPLICATION' /\u003e\n \u003cadd key = 'OAuth2ClientId' value = '******' /\u003e\n \u003cadd key = 'OAuth2ClientSecret' value = '******' /\u003e\n \u003cadd key = 'OAuth2RefreshToken' value = '******' /\u003e\n\n Make sure you also set the `LOGIN_CUSTOMER_ID` header in your `App.config`\n file. See [the configuration guide](/google-ads/api/docs/client-libs/dotnet/configuration#settings) to learn more. \n\n ```\n \u003cadd key = 'LoginCustomerId' value = 'INSERT_LOGIN_CUSTOMER_ID_HERE' /\u003e\n ```\n\n Refer to the [configuration guide](/google-ads/api/docs/client-libs/dotnet/configuration) for\n alternate configuration options.\n\nGenerate OAuth2 credentials for interactive applications\n--------------------------------------------------------\n\nIf you don't know the Google Ads account to make API calls to in advance, you can\ndiscover it at runtime using the credentials of the signed in user for the\nsession. See\n[`AuthenticateInAspNetCoreApplication`](https://github.com/googleads/google-ads-dotnet/tree/HEAD/Google.Ads.GoogleAds/examples/Authentication/AuthenticateInAspNetCoreApplication)\nfor an example where the currently signed in user is authenticated and the OAuth2\ncredentials are obtained at runtime."]]