設定授權
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Search Ads 360 API 要求所有要求都必須指定 OAuth 2.0 存取權杖進行驗證。您可以按照任何標準 OAuth 2.0 驗證工作流程產生權杖,然後將其傳遞至 Search Ads 360 API。我們建議您採用下方所述的工作流程,因為這類工作流程適合用於全自動轉換上傳和報表下載作業。
如要瞭解下列工作流程的替代方案,請參閱「針對已安裝的應用程式使用 OAuth 2.0」或「
針對伺服器對伺服器應用程式使用 OAuth 2.0」。若您使用其他工作流程,請在要求 OAuth 2.0 授權碼時,將下列值指定為 scope
參數:
https://www.googleapis.com/auth/doubleclicksearch
如果您遵循伺服器對伺服器轉送,請將服務帳戶新增為 Search Ads 360 使用者。
建議的授權工作流程
- 前往 Google API 控制台,然後選取您的專案。
如果您尚未建立 Google API 控制台專案和 OAuth 憑證,請按照「為用戶端建立 Google API 控制台專案和 OAuth 憑證」一文中的操作說明進行操作。
如要找出專案的 OAuth 用戶端 ID 和密鑰,請按照下列步驟操作:
- 開啟「憑證」頁面。
- 在「Name」欄中,按一下 OAuth 用戶端的名稱。
- 頁面上會列出用戶端 ID 和密鑰。
- 開啟網路瀏覽器,然後使用登入 Google
帳戶,該帳戶具備存取 Search Ads 360 資料的權限。
這是 API 用戶端用於向 Search Ads 360 驗證的 Google 帳戶。
如果 Google 帳戶持有人離職,而您移除了帳戶的 Search Ads 360 存取權,就必須重複這項授權工作流程,並指定其他 Google 帳戶。
- 如要取得重新整理權杖,請呼叫 Search Ads 360 公用程式指令碼,如下所示:
sa360Api.py --login
指令碼會引導您使用 OAuth 用戶端 ID 和密碼取得更新憑證。此重新整理權杖僅適用於您在上一個步驟中登入的 Google 帳戶。
在這個程序中,指令碼會產生網址,並指示您透過網路瀏覽器造訪該網址。
-
當瀏覽器要求您允許 OAuth 用戶端存取 Search Ads 360 資料時,
請務必顯示您稍早登入的 Google 帳戶。(如果您登入多個 Google 帳戶,系統可能會顯示其他帳戶)。
程序結束時,sa360Api.py
指令碼會輸出以半形逗號分隔的字串。第一個值是您提供的客戶端 ID,第二個值是您提供的客戶端密鑰,第三個值則是重新整理權杖。在以下範例輸出內容中,更新權杖以粗體文字顯示:
123456789123.apps.googleusercontent.com,ABCDEFGHIJKLMNOPQR_abcdef,1/HIJklM01OPQR23NOP456rst890uvw
- 將用戶端 ID、用戶端密鑰和更新權杖儲存在後端資料庫或其他可供應用程式存取的安全位置。
如果您打算使用 sa360Api.py
將 JSON 要求範例傳送至 Search Ads 360 API,請將整個逗號分隔字串存放在方便的位置。每次叫用指令碼時,您都會將整個字串做為參數傳遞。
- 在應用程式中加入程式碼,執行下列操作:
- 使用用戶端 ID、用戶端密碼和更新憑證,取得新的 OAuth 2.0 存取權杖。
- 使用新的存取權杖,將要求傳送至 Search Ads 360 API。
如果您使用的是用戶端程式庫,請參閱下一節「設定應用程式」,瞭解如何將此授權碼新增至應用程式。
如果您未使用任何用戶端程式庫,請參閱「為已安裝的應用程式使用 OAuth 2.0」,瞭解如何取得新的存取權杖。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-11-07 (世界標準時間)。
[null,null,["上次更新時間:2024-11-07 (世界標準時間)。"],[[["\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."]]