googleads/googleads-shopping-samples
ที่เก็บบน GitHub มีโค้ดตัวอย่างสำหรับการดำเนินการทั่วไปสำหรับลูกค้าแต่ละราย
ไลบรารี ตัวอย่างเช่น ตัวอย่างใน
googleads-shopping-samples/python/shopping/content/products/ ระบุโค้ด
สำหรับการดำเนินการทั่วไปโดยใช้
products
ด้วย Python ในคู่มือนี้ คุณจะเริ่มต้นด้วยไฟล์เปล่าและบิลด์
ตัวอย่างที่แทรกผลิตภัณฑ์ใหม่ๆ เพื่อให้คุณเห็น
ของโครงสร้างและองค์ประกอบที่จำเป็นของแอปพลิเคชัน ซึ่งจะผสานรวมกับ
Content API ผลลัพธ์สุดท้ายจะคล้ายกับตัวอย่างใน
products/insert.py ตัวอย่าง จากนั้นคุณสามารถใช้
โปรแกรมสำรวจ API
สำหรับเมธอด products.list
เพื่อยืนยันว่าเพิ่มผลิตภัณฑ์เรียบร้อยแล้ว
หากต้องการโทรครั้งแรก ให้ทำตามขั้นตอนต่อไปนี้
ใน googleads-shopping-samples/python/shopping/content/products/ ให้สร้างไฟล์ my-insert.py ที่ว่างเปล่า เพิ่มโค้ดทั้งหมดใน ทำตามขั้นตอนในไฟล์นี้
เพิ่มข้อความการนำเข้าสำหรับโมดูลที่ต้องการ
ที่ส่วนต้นของ my-insert.py ให้เพิ่มโค้ดต่อไปนี้
from __future__ import print_function
import sys
# The common module provides setup functionality used by the samples,
# such as authentication and unique id generation.
from shopping.content import commonกำหนดรหัสผลิตภัณฑ์ที่ไม่ซ้ำกันและสร้างพจนานุกรมที่มีผลิตภัณฑ์ ของเรา
ที่ส่วนท้ายของ 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 รหัสผู้ขายจากไฟล์การกำหนดค่า สร้างคำขอ และดำเนินการ คำขอเรียก API
ที่ส่วนท้ายของ my-insert.py ให้เพิ่มโค้ดต่อไปนี้
def main(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)หากต้องการเรียกใช้สคริปต์และเรียกใช้การเรียก API จากหน้าต่างเทอร์มินัล ให้ไปที่ ไปยัง googleads-shopping-samples/python/ และเรียกใช้
python -m shopping.content.products.my-insert
หากการเรียกใช้สำเร็จ บริการจะพิมพ์ข้อความต่อไปนี้ไปยังเครื่องชำระเงิน ผลิตภัณฑ์ที่มีรหัสข้อเสนอ "offerId" ก็สร้างขึ้น
หากต้องการยืนยันว่าเพิ่มผลิตภัณฑ์เรียบร้อยแล้ว ให้ใช้โปรแกรมสำรวจ API สำหรับ เมธอด
products.list
เพื่อส่งคืนผลิตภัณฑ์ทั้งหมดใน Merchant Center ของคุณได้ใน โปรแกรมสำรวจ API สำหรับเมธอด
products.list
ป้อนค่าต่อไปนี้- ป้อน
merchantId
- ในส่วนข้อมูลเข้าสู่ระบบ ให้เลือก Google OAuth 2.0 และคีย์ API
- คลิกปุ่มดำเนินการ
- หากได้รับข้อความแจ้ง ให้ลงชื่อเข้าใช้ด้วยบัญชี Google ที่เชื่อมโยงกับผู้ขาย ศูนย์บริการ
หากเพิ่มผลิตภัณฑ์สำเร็จ ข้อมูลผลิตภัณฑ์จะปรากฏใน API คำตอบของนักสำรวจ
- ป้อน
ผู้ขายมีหน้าที่รับผิดชอบในการปฏิบัติตาม Shopping โฆษณาและฟรี นโยบายข้อมูล Google Shopping ขอสงวนสิทธิ์ในการบังคับใช้นโยบายเหล่านี้และตอบสนองอย่างเหมาะสม หากเราพบเนื้อหาหรือพฤติกรรมที่ละเมิดนโยบายเหล่านี้