تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
عميل Google API (مثل Python)
في ما يلي بعض النماذج التي تستخدم مكتبة برامج Google API. في ما يلي الأمثلة
مكتوبة بلغة بايثون، لكنها قد تكون متشابهة في لغات برمجة أخرى،
مثل PHP.
لاستخدام برامج واجهة Google 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
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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"]]