이 가이드에서는 자체 사용자 인증 정보와 데스크톱 흐름 또는 웹 흐름을 사용하여 API 액세스를 위한 OAuth 2.0을 설정하는 방법을 안내합니다. OAuth 2.0 사용자 인증 정보의 허용된 범위를 취소, 삭제 또는 변경해야 하는 경우를 제외하고는 이 단계를 한 번만 수행하면 됩니다.
이 코드 예시는 브라우저에서 URL을 자동으로 엽니다. 브라우저 세션에 로그인하지 않은 경우 웹페이지에서 Google 계정에 로그인하라는 메시지가 표시됩니다. 이미 로그인한 경우 로그인 메시지가 건너뛰고 앱이 사용자를 대신하여 Google Ads 계정에 액세스하도록 승인해야 하는 URL로 리디렉션됩니다.
Google Ads에 액세스하는 데 사용하는 Google 계정으로 로그인합니다. 일반적으로 이는 계정 계층 구조에서 관리해야 하는 모든 계정이 포함된 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' />
API 호출을 수행할 Google Ads 계정을 미리 알지 못하는 경우 세션에 로그인한 사용자의 사용자 인증 정보를 사용하여 런타임에 계정을 검색할 수 있습니다. 현재 로그인한 사용자가 인증되고 OAuth2 사용자 인증 정보가 런타임에 획득되는 예는 AuthenticateInAspNetCoreApplication을 참고하세요.
[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."]]