設定用戶端程式庫

我們建議您使用 Google API 用戶端程式庫來設定 Content API for Shopping。本指南以 Python Content API 用戶端程式庫為例,但適用於多種熱門程式設計語言,並簡化了驗證、傳送和剖析回應等常見的 API 工作。如需設定其他語言的用戶端程式庫,請參閱 GitHub 上的 googleads/googleads-shopping-samples 存放區內的語言 README.md

如要設定 Python 適用的 Google API 用戶端程式庫,請完成下列步驟:

  1. 為用戶端程式庫的設定和驗證檔案建立目錄。在主目錄中,建立以下目錄:

    ~/shopping-samples/content/

  2. 如要下載服務帳戶憑證,請完成下列步驟:

    1. Merchant Center 的「設定」選單中,選取 [Content API]
    2. 按一下 [驗證]
    3. 按一下「[+] 建立 API 金鑰」
    4. 看到系統提示時,請詳閱並接受《服務條款》。

    新的金鑰會自動下載。

  3. 將下載的憑證檔案重新命名為 service-account.json

  4. service-account.json 檔案移至您的 home directory/shopping-samples/content/

  5. home directory/shopping-samples/content/ 中,建立一個空白的 merchant-info.json 檔案。

  6. merchant-info.json 中加入以下文字:

    {
    "merchantId": your Merchant Center merchant ID,
    "accountSampleUser": "the email address associated with your Merchant Center account"
    }
    
  7. googleads/googleads-shopping-samples GitHub 存放區複製 (或下載) 到您電腦上的任何位置,但不見於您的主目錄或 ~/shopping-samples/content/

  8. 如果您已下載並解壓縮存放區,而非複製,請將未壓縮的目錄重新命名為 googleads-shopping-samples

  9. 如要安裝所需的範例依附元件,請在終端機視窗中前往 googleads-shopping-samples/python/ 並執行下列指令:

    pip install -r requirements.txt
    

現在,您已設定 Python 專用的 Google API 用戶端程式庫,可以搭配 Content API 使用。在下一節中,您將建立並要求插入新產品。