Configurar autorização
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
A API Search Ads 360 exige que todas as solicitações especifiquem um token de acesso do OAuth 2.0 (em inglês) para autenticação. Você pode seguir qualquer fluxo de trabalho de autenticação padrão do OAuth 2.0
para gerar o token e transmiti-lo à API Search Ads 360. Recomendamos o fluxo de trabalho descrito abaixo porque ele é adequado para uploads de conversões e downloads de relatórios totalmente automatizados.
Para alternativas ao fluxo de trabalho descrito abaixo, consulte Usar
o OAuth 2.0 para aplicativos instalados ou
Usar o OAuth 2.0 para aplicativos de servidor para servidor. Se você usar um fluxo de trabalho alternativo,
especifique o seguinte valor como o parâmetro scope
ao solicitar um código de autorização do OAuth
2.0:
https://www.googleapis.com/auth/doubleclicksearch
Se você seguir a rota de servidor para servidor, adicione a conta de serviço como um usuário do Search Ads 360.
Fluxo de trabalho de autorização recomendado
- Acesse o Console de APIs do Google e selecione seu projeto.
Se você ainda não tiver criado um projeto do Console de APIs do Google e as credenciais do OAuth, siga as instruções em Criar um projeto no Console de APIs do Google e credenciais de OAuth para seu cliente.
Para encontrar o ID do cliente e a chave secreta do OAuth do projeto, faça o seguinte:
- Abra a página Credenciais.
- Na coluna Nome, clique no nome do cliente OAuth.
- O ID e a chave secreta do cliente estão listados na página.
- Abra um navegador da Web e faça login no Google
com uma Conta do Google que tenha
permissão para acessar dados no Search Ads 360.
Essa é a Conta do Google que o cliente da API vai usar para fazer a autenticação com o Search Ads 360.
Se o titular da Conta do Google sair da sua empresa e você remover o acesso do Search Ads 360 da conta, será necessário repetir esse fluxo de trabalho de autorização e especificar uma Conta do Google diferente.
- Para conseguir um token de atualização, invoque o script de utilitário do Search Ads 360 da seguinte maneira:
sa360Api.py --login
O script orienta você no processo de uso do ID e da chave secreta do cliente OAuth para
receber um token de atualização. O token de atualização é válido apenas para a Conta do Google em que você fez login
na etapa anterior.
Como parte desse processo, o script gera um URL e o instrui a acessar o URL em um navegador da Web.
-
Quando o navegador solicitar que você permita o acesso do cliente OAuth aos dados do Search Ads 360,
verifique se a Conta do Google em que você fez login aparece. Se você tiver feito login em várias Contas do Google, uma conta diferente poderá ser exibida.
No final do processo, o script sa360Api.py
gera uma string separada por vírgulas. O primeiro valor é o ID do cliente fornecido, o segundo é a chave secreta do cliente fornecida e o terceiro é o token de atualização. No exemplo de saída
a seguir, o token de atualização está em texto em negrito:
123456789123.apps.googleusercontent.com,ABCDEFGHIJKLMNOPQR_abcdef,1/HIJklM01OPQR23NOP456rst890uvw
- Armazene o ID, a chave secreta e o token de atualização do cliente em um banco de dados de back-end ou
em outro local seguro que possa ser acessado pelo aplicativo.
Mantenha toda a string delimitada por vírgulas em um local conveniente se planeja usar sa360Api.py
para enviar amostras de solicitações JSON para a API Search Ads 360. Você transmitirá toda a string como um parâmetro sempre que invocar o script.
- Adicione um código ao seu aplicativo que faça o seguinte:
- Use o ID do cliente, a chave secreta do cliente e o token de atualização para receber um novo token de acesso do OAuth 2.0.
- Envie solicitações à API Search Ads 360 usando o novo token de acesso.
Se você estiver usando as bibliotecas de cliente, a próxima seção, Configurar seu aplicativo,
descreve como adicionar esse código de autorização ao seu aplicativo.
Se você não estiver usando uma das bibliotecas de cliente, consulte Usar o OAuth 2.0 para aplicativos instalados para ver sugestões sobre como conseguir um novo token de acesso.
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
Última atualização 2024-11-07 UTC.
[null,null,["Última atualização 2024-11-07 UTC."],[[["\u003cp\u003eThe Search Ads 360 API requires OAuth 2.0 access tokens for authentication, obtainable through standard OAuth 2.0 workflows or the recommended workflow outlined in the document.\u003c/p\u003e\n"],["\u003cp\u003eThe recommended workflow involves obtaining a refresh token using the provided utility script and storing it securely along with the client ID and secret.\u003c/p\u003e\n"],["\u003cp\u003eApplications should be designed to use the stored credentials to obtain fresh access tokens for API requests, as detailed in the "Set Up Your Application" section or relevant OAuth 2.0 documentation.\u003c/p\u003e\n"],["\u003cp\u003eAlternative workflows for installed or server-to-server applications are available with specific scope requirements and user management considerations.\u003c/p\u003e\n"]]],["The Search Ads 360 API requires OAuth 2.0 access tokens for authentication. The recommended workflow involves creating a Google API Console project and obtaining OAuth credentials. Users sign into a Google Account with Search Ads 360 access, then use the `sa360Api.py` script to generate a refresh token. The script outputs client ID, client secret, and refresh token. Store these securely, and use them in your application to obtain a fresh OAuth access token for API requests.\n"],null,["# Set Up Authorization\n\nThe Search Ads 360 API requires all requests to specify an [OAuth 2.0](/accounts/docs/OAuth2)\naccess token for authentication. You can follow any standard OAuth 2.0 authentication workflow\nto generate the token and pass it to the Search Ads 360 API. We recommend the workflow described\nbelow because it is suitable for fully automated conversion uploads and report downloads.\n\n\nFor alternatives to the workflow described below, see [Using\nOAuth 2.0 for Installed Applications](https://developers.google.com/accounts/docs/OAuth2InstalledApp) or\n[Using OAuth 2.0 for Server to Server Applications](https://developers.google.com/identity/protocols/OAuth2ServiceAccount). If you use an alternate workflow,\nspecify the following value as the `scope` parameter when you request an OAuth\n2.0 authorization code: \n\n`https://www.googleapis.com/auth/doubleclicksearch`\n\nIf you follow the server to server route, add the service account as a Search Ads 360 user.\n\nRecommended authorization workflow\n----------------------------------\n\n1. Go to the [Google API Console](https://console.cloud.google.com/) and select your project.\n\n\n If you haven't already created a Google API Console project and OAuth credentials, follow\n the instructions in [Create a Google API\n Console project and OAuth credentials for your client](/search-ads/v2/prereqs#project).\n\n To find your project's OAuth client ID and secret, do the following:\n 1. Open the [Credentials page](https://console.cloud.google.com/apis/credentials).\n 2. In the **Name** column, click the name of your OAuth client.\n 3. The client ID and secret are listed on the page.\n2. Open a web browser and [sign into Google](https://accounts.google.com/ServiceLogin)with a Google Account that [has\n permission to access data](/search-ads/v2/prereqs#permissions) in Search Ads 360.\n\n This is the Google Account your API client will use to authenticate with Search Ads 360.\n If the Google Account holder leaves your company and you remove Search Ads 360 access\n from the account, you will need to repeat this authorization workflow and specify a\n different Google Account.\n3. Obtain a refresh token by invoking the [Search Ads 360 utility script](/search-ads/v2/prereqs#ds3py) as follows:\n\n\n `sa360Api.py --login`\n\n\n The script takes you through the process of using the Oauth client ID and secret to\n obtain a refresh token. The refresh token is valid only for the Google Account you signed\n into during the previous step.\n\n As part of this process, the script generates a URL and instructs you to\n visit the URL in a web browser.\n4. When the browser asks you to allow OAuth client access to Search Ads 360 data,\n make sure the Google Account you signed into earlier appears. (If you're signed into multiple\n Google Accounts, you might be presented with a different account.)\n\n\n At the end of the process, the `sa360Api.py` script outputs a comma-delimited\n string. The first value is the client ID you provided, the second value is the client\n secret you provided, and the third value is the refresh token. In the following example\n output, the refresh token is in **bold text** : \n\n `123456789123.apps.googleusercontent.com,ABCDEFGHIJKLMNOPQR_abcdef,`**1/HIJklM01OPQR23NOP456rst890uvw**\n5. Store the client ID, client secret, and refresh token in a backend database or other secure location that's accessible to your application.\n Keep the entire comma-delimited string in a convenient location if you plan to use\n `sa360Api.py` to send sample JSON requests to the Search Ads 360 API. You'll pass the\n entire string as a parameter each time you invoke the script.\n\n6. Add code to your application that does the following:\n 1. Use the client ID, client secret, and refresh token to obtain a fresh OAuth 2.0 access token.\n 2. Send requests to the Search Ads 360 API using the fresh access token.\n\n\n If you're using the client libraries, the next section, [Set Up Your Application](/search-ads/v2/configure),\n describes how to add this authorization code to your application.\n\n\n If you're not using one of the client libraries, see [Using OAuth 2.0 for Installed Applications](https://developers.google.com/accounts/docs/OAuth2InstalledApp) for\n suggestions on obtaining a fresh access token."]]