Python 用戶端程式庫設定

安裝 Python 用戶端程式庫

如要在本機環境中安裝 Python 用戶端程式庫:

  1. 擷取 Python 用戶端程式庫 tarball。
  2. 在相同目錄中執行下列指令:

    python -m pip install .
    
  3. 按照終端機的提示完成安裝程序。

使用 YAML 檔案進行設定

您可以指定在初始化用戶端時,包含傳送要求所需的必要驗證資訊的 YAML 檔案。使用 load_from_file 方法初始化用戶端時,系統會存取這個檔案。按照下方提供的範例建立 YAML 檔案,指定重新整理權杖、用戶端 ID 和用戶端密鑰。

如要指定 search-ads-360.yaml 檔案所在的位置,您可以在呼叫方法時,以字串形式將路徑傳遞給方法:

from util_searchads360 import SearchAds360Client
client = SearchAds360Client.load_from_file("path/to/search-ads-360.yaml")

如果您未提供路徑,程式庫會在您的 $HOME 目錄中查看檔案的 $HOME 目錄:

from util_searchads360 import SearchAds360Client
client = SearchAds360Client.load_from_file()

設定欄位

用戶端程式庫設定支援下列欄位。

一般欄位:

  • refresh_token:您的 OAuth 更新權杖。
  • client_id:您的 OAuth 用戶端 ID。
  • client_secret:您的 OAuth 用戶端密鑰。
  • login_customer_id:請參閱 login-customer-id 說明文件

電腦與網頁應用程式流程支援的金鑰

如果您使用的是電腦版或網頁版應用程式流程,則支援的金鑰如下:

# Credential for accessing Google's OAuth servers.
# Provided by console.cloud.google.com.
client_id: INSERT_CLIENT_ID_HERE

# Credential for accessing Google's OAuth servers.
# Provided by console.cloud.google.com.
client_secret: INSERT_CLIENT_SECRET_HERE

# Renewable OAuth credential associated with 1 or more Search Ads accounts.
refresh_token: INSERT_REFRESH_TOKEN_HERE

# Required for manager accounts only: Specify the login customer ID used to
# authenticate API calls. This will be the customer ID of the authenticated
# manager account. You can also specify this later in code if your application
# uses multiple manager account + OAuth pairs.
#
# login_customer_id: INSERT_LOGIN_CUSTOMER_ID_HERE