تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يحتوي مستودع googleads/googleads-shopping-samples
على GitHub على عيّنات من الرموز البرمجية للعمليات الشائعة لكل مكتبة من مكتبات البرامج. على سبيل المثال، تقدّم النماذج في
googleads-shopping-samples/python/shopping/content/products/ رمزًا برمجيًا
لعمليات شائعة باستخدام
مصدر products
مع Python. في هذا الدليل، ستبدأ بملف فارغ وتنشئ مثالاً يضيف منتجًا جديدًا، وذلك لتتمكّن من الاطّلاع على البنية الأساسية والمكوّنات المطلوبة للتطبيقات التي تتكامل مع Content API. ستكون النتيجة النهائية مشابهة للمثال الوارد في ملف النموذج products/insert.py. يمكنك بعد ذلك استخدام
مستكشف واجهات برمجة التطبيقات
لطريقة products.list للتأكّد من أنّه تمت إضافة المنتج بنجاح.
لإجراء مكالمتك الأولى، أكمل الخطوات التالية:
في الدليل googleads-shopping-samples/python/shopping/content/products/، أنشئ ملفًا فارغًا باسم my-insert.py. أضِف كل الرموز في الخطوات التالية إلى هذا الملف.
أضِف عبارات الاستيراد للوحدات المطلوبة.
في بداية my-insert.py، أضِف الرمز التالي:
from__future__importprint_functionimportsys# The common module provides setup functionality used by the samples,# such as authentication and unique id generation.fromshopping.contentimportcommon
حدِّد معرّف منتج فريدًا وأنشئ قاموسًا يتضمّن تعريف المنتج.
في نهاية my-insert.py، أضِف الرمز التالي:
offer_id='book#%s'%common.get_unique_id()product={'offerId':offer_id,'title':'A Tale of Two Cities','description':'A classic novel about the French Revolution','link':'http://my-book-shop.com/tale-of-two-cities.html','imageLink':'http://my-book-shop.com/tale-of-two-cities.jpg','contentLanguage':'en','targetCountry':'US','channel':'online','availability':'in stock','condition':'new','googleProductCategory':'Media > Books','gtin':'9780007350896','price':{'value':'2.50','currency':'USD'},'shipping':[{'country':'US','service':'Standard shipping','price':{'value':'0.99','currency':'USD'}}],'shippingWeight':{'value':'200','unit':'grams'}}
أنشئ دالة يتم تشغيلها عند تشغيل النص البرمجي من سطر الأوامر. تنشئ الدالة عنصر خدمة للتفاعل مع Content API، وتحصل على معرّف التاجر من ملف الإعداد، وتنشئ الطلب، وتنفّذ الطلب لإجراء طلب البيانات من واجهة برمجة التطبيقات.
في نهاية my-insert.py، أضِف الرمز التالي:
defmain(argv):# Construct the service object to interact with the Content API.service,config,_=common.init(argv,__doc__)# Get the merchant ID from merchant-info.json.merchant_id=config['merchantId']# Create the request with the merchant ID and product object.request=service.products().insert(merchantId=merchant_id,body=product)# Execute the request and print the result.result=request.execute()print('Product with offerId "%s" was created.'%(result['offerId']))# Allow the function to be called with arguments passed from the command line.if__name__=='__main__':main(sys.argv)
لتشغيل النص البرمجي وتنفيذ طلب البيانات من واجهة برمجة التطبيقات، انتقِل من نافذة طرفية إلى googleads-shopping-samples/python/ وشغِّل ما يلي:
python-mshopping.content.products.my-insert
إذا نجحت المكالمة، ستعرض الخدمة الرسالة التالية في نافذة الأوامر:
تم إنشاء المنتج الذي يحمل رقم تعريف العرض "offerId".
للتأكّد من أنّه تمت إضافة المنتج بنجاح، استخدِم "مستكشف واجهات برمجة التطبيقات" مع الطريقة products.list لعرض جميع المنتجات في حسابك على Merchant Center.
في قسم بيانات الاعتماد، اختَر Google OAuth 2.0 ومفتاح واجهة برمجة التطبيقات.
انقر على الزر تنفيذ.
سجِّل الدخول باستخدام حساب Google المرتبط بحسابك على Merchant Center عندما يُطلب منك ذلك.
إذا تمت إضافة المنتج بنجاح، ستظهر بيانات المنتج في استجابة "مستكشف واجهة برمجة التطبيقات".
يتحمّل التجّار مسؤولية الالتزام بسياسات إعلانات Shopping والبيانات المجانية. يحتفظ محرّك بحث Google Shopping بالحق في فرض هذه السياسات واتّخاذ الإجراءات اللازمة إذا عثرنا على محتوى أو سلوك يخالف هذه السياسات.
تاريخ التعديل الأخير: 2025-08-13 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-13 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThe Merchant API is the new version of the Content API for Shopping and represents the future of product data integration.\u003c/p\u003e\n"],["\u003cp\u003eThis guide provides a step-by-step example of inserting a new product using the Merchant API with Python.\u003c/p\u003e\n"],["\u003cp\u003eSample code and helpful modules are available in the \u003ccode\u003egoogleads/googleads-shopping-samples\u003c/code\u003e repository on GitHub.\u003c/p\u003e\n"],["\u003cp\u003eMerchants are responsible for adhering to Shopping ads and free listings policies when using the API.\u003c/p\u003e\n"],["\u003cp\u003eNew products inserted through the API are, by default, added to a new primary feed in Merchant Center.\u003c/p\u003e\n"]]],["The guide demonstrates inserting a product using the Merchant API's `products.insert` method via Python. It instructs creating a `my-insert.py` file, importing necessary modules, defining a unique product ID, and constructing a product dictionary with details like title, description, price, and shipping. The script then creates a service object, gets the merchant ID, builds a request, executes it, and verifies success by printing a confirmation message. Finally, using the API Explorer to check if the product is in the `products.list`.\n"],null,["# Make an API call\n\nThe [googleads/googleads-shopping-samples](//github.com/googleads/googleads-shopping-samples)\nrepo on GitHub contains sample code for common operations for each client\nlibrary. For example, the samples in\n**googleads-shopping-samples/python/shopping/content/products/** provide code\nfor common operations using the\n[`products`](/shopping-content/reference/rest/v2.1/products)\nresource with Python. In this guide, you start with an empty file and build\nup an example that inserts a new product, so that you can see the basic\nstructure and required components of applications that integrate with the\nContent API. The end result will be similar to the example in the\n**products/insert.py** sample file. You can then use the\n[API Explorer](/shopping-content/reference/rest/v2.1/products/list?apix=true)\nfor the `products.list` method to verify that the product was added successfully.\n| **Note:** This example uses the **python/shopping/content/common.py** module to create a service object that handles authentication and provides an interface for making calls to the Content API. The **common.py** module also includes other helpful methods for common operations, such as generating unique IDs, checking whether an account is a multi-client account (MCA), and retrying requests.\n\nTo make your first call, complete the following steps:\n\n1. In the **googleads-shopping-samples/python/shopping/content/products/**\n directory, create an empty **my-insert.py** file. Add all of the code in the\n following steps to this file.\n\n2. Add the import statements for the required modules.\n\n At the beginning of **my-insert.py**, add the following code: \n\n from __future__ import print_function\n import sys\n\n # The common module provides setup functionality used by the samples,\n # such as authentication and unique id generation.\n from shopping.content import common\n\n3. Define a unique product ID and create a dictionary with the product\n definition.\n\n At the end of **my-insert.py**, add the following code: \n\n offer_id = 'book#%s' % common.get_unique_id()\n product = {\n 'offerId':\n offer_id,\n 'title':\n 'A Tale of Two Cities',\n 'description':\n 'A classic novel about the French Revolution',\n 'link':\n 'http://my-book-shop.com/tale-of-two-cities.html',\n 'imageLink':\n 'http://my-book-shop.com/tale-of-two-cities.jpg',\n 'contentLanguage':\n 'en',\n 'targetCountry':\n 'US',\n 'channel':\n 'online',\n 'availability':\n 'in stock',\n 'condition':\n 'new',\n 'googleProductCategory':\n 'Media \u003e Books',\n 'gtin':\n '9780007350896',\n 'price': {\n 'value': '2.50',\n 'currency': 'USD'\n },\n 'shipping': [{\n 'country': 'US',\n 'service': 'Standard shipping',\n 'price': {\n 'value': '0.99',\n 'currency': 'USD'\n }\n }],\n 'shippingWeight': {\n 'value': '200',\n 'unit': 'grams'\n }\n }\n\n4. Create a function that runs when the script is run from the command line. The\n function constructs a service object to interact with the Content API, gets the\n merchant ID from the configuration file, constructs the request, and executes\n the request to make the API call.\n\n At the end of **my-insert.py**, add the following code: \n\n def main(argv):\n # Construct the service object to interact with the Content API.\n service, config, _ = common.init(argv, __doc__)\n\n # Get the merchant ID from merchant-info.json.\n merchant_id = config['merchantId']\n\n # Create the request with the merchant ID and product object.\n request = service.products().insert(merchantId=merchant_id, body=product)\n\n # Execute the request and print the result.\n result = request.execute()\n print('Product with offerId \"%s\" was created.' % (result['offerId']))\n\n # Allow the function to be called with arguments passed from the command line.\n if __name__ == '__main__':\n main(sys.argv)\n\n5. To run the script and execute the API call, from a terminal window, navigate\n to **googleads-shopping-samples/python/** and run:\n\n python -m shopping.content.products.my-insert\n\n If the call was successful, the service prints the following message to the terminal:\n **Product with offerId \"\u003cvar translate=\"no\"\u003eofferId\u003c/var\u003e\" was created.**\n6. To verify that the product was added successfully, use the API Explorer for\n the `products.list` method to return all of the products in your Merchant Center\n account.\n\n | **Note:** It may take up to a few minutes after the `products.insert` call completes before the product is available through `products.list` or in Merchant Center.\n\n In the\n [API Explorer for the `products.list` method](/shopping-content/reference/rest/v2.1/products/list?apix=true),\n enter the following values:\n 1. Enter your `merchantId`.\n\n | **Note:** All other request parameters are optional.\n 1. In the **Credentials** section, select **Google OAuth 2.0** and **API key**.\n 2. Click the **Execute** button.\n 3. If prompted, sign in with the Google account associated with your Merchant Center account.\n\n If the product was added successfully, the product data appears in the API\n explorer response.\n\nMerchants are responsible for complying with the [Shopping\nads](//support.google.com/merchants/answer/6149970) and [free\nlistings](//support.google.com/merchants/answer/9261529) policies. Google\nShopping reserves the right to enforce these policies and respond appropriately\nif we find content or behavior that violates these policies.\n| **Note:** By default, new products inserted via the Content API are added to a new primary feed in Merchant Center. For more information on using different feed types with the Content API, see [Best Practices](/shopping-content/guides/best-practices)."]]