コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Google API クライアント(Python など)
Google API クライアント ライブラリを使用するサンプルを次に示します。次の例をご覧ください。
Python で記述されていますが 他のプログラミング言語と
使用できます。
Google API クライアントを使用するには、
API キーとサービス
(
クイックスタート
requirements.txt:
google-api-python-client>=2.98.0
insert.py:
from googleapiclient.discovery import build
from google.oauth2 import service_account
# This must be a valid service json document
SERVICE_ACCOUNT_FILE="/.../google.....json"
SCOPES=["https://www.googleapis.com/auth/content"]
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
url="https://css.googleapis.com/$discovery/rest?version=v1"
# This must be a valid API key
key="..."
with build(serviceName= 'css', version= 'v1', discoveryServiceUrl=url,
developerKey=key,
credentials=credentials) as service:
# Add more parameters
# Use your CSS domain ID
request = service.accounts().cssProductInputs().insert(parent="accounts/1234567")
response = request.execute()
print(f"{response}")
list.py:
# Code from above
with build(serviceName= 'css', version= 'v1', discoveryServiceUrl=url,
developerKey=key,
credentials=credentials) as service:
# Use your CSS domain ID
request = service.accounts().cssProducts().list(parent="accounts/1234567")
response = request.execute()
print(f"---\nResponse: {response}")
# Use your CSS domain ID
# the id is built using your country/language (it in this example) and the
# id you gave when uploading the item.
request = service.accounts().cssProducts().get(name="accounts/1234567/cssProducts/it~IT~myproductid")
response = request.execute()
print(f"---\nResponse: {response}")
```language=python
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-25 UTC。
[null,null,["最終更新日 2025-07-25 UTC。"],[[["\u003cp\u003eThis documentation provides Python examples of using the Google API Client library for interactions with Google services.\u003c/p\u003e\n"],["\u003cp\u003eUsers need an API key and a service account document for authentication, as detailed in the linked quickstart guide.\u003c/p\u003e\n"],["\u003cp\u003eCode snippets illustrate how to build a service object using credentials and an API key to perform actions like inserting and listing data with Google services.\u003c/p\u003e\n"],["\u003cp\u003eThe provided \u003ccode\u003einsert.py\u003c/code\u003e and \u003ccode\u003elist.py\u003c/code\u003e examples demonstrate creating, executing, and printing responses from Google API requests.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples may be adapted for other programming languages with similar concepts, as noted with the PHP example.\u003c/p\u003e\n"]]],[],null,["Google API Client (e.g. Python)\n-------------------------------\n\nHere are some samples which use the Google API client library. These examples\nare written in python, but they may be similar in other programming languages,\nsuch as PHP.\n\nFor using the Google API clients, you will need both an\n[API key](https://cloud.google.com/docs/authentication/api-keys) and a service\naccount document, as described in the [Permissions section in\nquickstart](/comparison-shopping-services/api/guides/quickstart)\n\nrequirements.txt:\n\n`google-api-python-client\u003e=2.98.0`\n\ninsert.py: \n\n from googleapiclient.discovery import build\n from google.oauth2 import service_account\n\n # This must be a valid service json document\n SERVICE_ACCOUNT_FILE=\"/.../google.....json\"\n SCOPES=[\"https://www.googleapis.com/auth/content\"]\n\n credentials = service_account.Credentials.from_service_account_file(\n SERVICE_ACCOUNT_FILE, scopes=SCOPES)\n\n url=\"https://css.googleapis.com/$discovery/rest?version=v1\"\n # This must be a valid API key\n key=\"...\"\n\n with build(serviceName= 'css', version= 'v1', discoveryServiceUrl=url,\n developerKey=key,\n credentials=credentials) as service:\n # Add more parameters\n # Use your CSS domain ID\n request = service.accounts().cssProductInputs().insert(parent=\"accounts/1234567\")\n response = request.execute()\n print(f\"{response}\")\n\nlist.py: \n\n # Code from above\n with build(serviceName= 'css', version= 'v1', discoveryServiceUrl=url,\n developerKey=key,\n credentials=credentials) as service:\n # Use your CSS domain ID\n request = service.accounts().cssProducts().list(parent=\"accounts/1234567\")\n response = request.execute()\n print(f\"---\\nResponse: {response}\")\n\n # Use your CSS domain ID\n # the id is built using your country/language (it in this example) and the\n # id you gave when uploading the item.\n request = service.accounts().cssProducts().get(name=\"accounts/1234567/cssProducts/it~IT~myproductid\")\n response = request.execute()\n print(f\"---\\nResponse: {response}\")\n ```language=python"]]