Para analizar nuestros productos y brindar comentarios sobre ellos, únete al canal oficial de Discord de Google Ads en el servidor de la Comunidad de Publicidad y Medición de Google.
Flujos de aplicaciones web y de escritorio de OAuth
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En esta guía, se explica cómo configurar OAuth 2.0 para el acceso a la API con tus propias credenciales y el flujo de escritorio o el flujo web. Solo debes realizar estos pasos una vez, a menos que revoques, borres o necesites cambiar los alcances permitidos para tus credenciales de OAuth 2.0.
Anota el ID de cliente y el secreto del cliente y, luego, vuelve a esta página.
Configura la biblioteca cliente
En una terminal, ejecuta el ejemplo de código GenerateUserCredentials, que te solicita tu ID de cliente y secreto del cliente de OAuth 2.0.
php GenerateUserCredentials.php
El ejemplo de código te solicita que visites una URL en la que debes autorizar a tu app para que acceda a tu cuenta de Google Ads en tu nombre.
Paste this URL in your browser:
https://accounts.google.com/o/oauth2/v2/auth?response_type=code&access_type=offline&client_id=...
Navega a la URL en una sesión de navegador privada o en una ventana de incógnito.
Accede con la Cuenta de Google que usas para ingresar a Google Ads. Por lo general, se trata de un correo electrónico de acceso a una cuenta de administrador de Google Ads que contiene todas las cuentas que necesitas administrar en su jerarquía de cuentas. Haz clic en Continuar en la pantalla de consentimiento de OAuth 2.0.
Se te redireccionará a una página con un mensaje que indica que la autorización se realizó correctamente.
Your refresh token has been fetched. Check the console output for further
instructions.
Regresa a la consola en la que ejecutas el ejemplo de código. Verás que el ejemplo de código se completó y muestra tu token de actualización y algunas instrucciones, seguidas de las instrucciones que deberás seguir para configurar la biblioteca cliente:
Your refresh token is: 1/Yw**********
Copy the text below into a file named "google_ads_php.ini" in your home directory, and
replace "INSERT_DEVELOPER_TOKEN_HERE" with your developer token:
[GOOGLE_ADS]
developerToken = "INSERT_DEVELOPER_TOKEN_HERE"
[OAUTH2]
Copy the following lines to your 'google_ads_php.ini' file:
clientId = "***********************apps.googleusercontent.com"
clientSecret = "****"
refreshToken = "****"
[null,null,["Última actualización: 2025-08-31 (UTC)"],[[["\u003cp\u003eThis guide explains how to set up OAuth2 for Google Ads API access using your own credentials through either a desktop or web flow.\u003c/p\u003e\n"],["\u003cp\u003eYou'll need to create OAuth2 credentials by configuring a Google API Console project and noting your client ID and secret.\u003c/p\u003e\n"],["\u003cp\u003eThe setup involves running a client library example that guides you through an authorization process using your Google account.\u003c/p\u003e\n"],["\u003cp\u003eUpon successful authorization, you'll receive a refresh token and instructions to configure your client library with the necessary properties.\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-php/blob/HEAD/examples/Authentication/GenerateUserCredentials.php) code example, which prompts you for your OAuth 2.0\n client ID and client secret.\n\n ```\n php GenerateUserCredentials.php\n ```\n2. The code example prompts you to visit a URL where you must authorize your app\n to access your Google Ads account on your behalf.\n\n ```\n Paste this URL in your browser:\n https://accounts.google.com/o/oauth2/v2/auth?response_type=code&access_type=offline&client_id=...\n ```\n\n Navigate to the URL in a private browser session or an incognito window.\n Sign in with the Google Account you use to access Google Ads. Usually, this is a login email\n to a Google Ads manager account that contains all the accounts you need to manage under\n 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 succeeded. \n\n ```\n Your refresh token has been fetched. Check the console output for further\n instructions.\n ```\n3. Return to the console where you're running the code example. You'll see that the code example\n has completed and is displaying your refresh token and some instructions, followed by the\n instructions you'll need to follow to configure the client library:\n\n ```\n Your refresh token is: 1/Yw**********\n Copy the text below into a file named \"google_ads_php.ini\" in your home directory, and\n replace \"INSERT_DEVELOPER_TOKEN_HERE\" with your developer token:\n\n [GOOGLE_ADS]\n developerToken = \"INSERT_DEVELOPER_TOKEN_HERE\"\n [OAUTH2]\n Copy the following lines to your 'google_ads_php.ini' file:\n clientId = \"***********************apps.googleusercontent.com\"\n clientSecret = \"****\"\n refreshToken = \"****\"\n ```"]]