設定用戶端程式庫

建議您使用 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 搭配使用。在下一節中,您將建立並傳送插入新產品的要求。