एपीआई कॉल करें

GitHub पर googleads/googleads-shopping-सैंपल रेपो में, हर क्लाइंट लाइब्रेरी पर सामान्य कार्रवाइयों के लिए सैंपल कोड शामिल होता है. उदाहरण के लिए, googleads-shopping-samples/python/shopping/content/products/ में मौजूद सैंपल, Python के साथ products संसाधन इस्तेमाल करके सामान्य ऑपरेशन के लिए कोड देते हैं. इस गाइड में, एक खाली फ़ाइल से शुरुआत की जाती है और फिर एक उदाहरण तैयार किया जाता है. इसमें एक नया प्रॉडक्ट शामिल किया जाता है. इससे, Content API से इंटिग्रेट किए जाने वाले ऐप्लिकेशन के बुनियादी स्ट्रक्चर और ज़रूरी कॉम्पोनेंट देखे जा सकते हैं. नतीजे के तौर पर मिलने वाला नतीजा, products/insert.py सैंपल फ़ाइल में दिए गए उदाहरण से मिलता-जुलता होगा. इसके बाद, products.list तरीके के लिए एपीआई एक्सप्लोरर का इस्तेमाल करके, यह पुष्टि की जा सकती है कि प्रॉडक्ट जोड़ दिया गया है.

अपना पहला कॉल करने के लिए, इन चरणों को पूरा करें:

  1. googleads-shopping-samples/python/shopping/content/products/ डायरेक्ट्री में, एक खाली googleads-shopping-samples/python/shopping/content/products/ फ़ाइल बनाएं. इस फ़ाइल में दिया गया सभी कोड जोड़ें.

  2. ज़रूरी मॉड्यूल के लिए इंपोर्ट स्टेटमेंट जोड़ें.

    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
    
  3. यूनीक प्रॉडक्ट आईडी तय करें और प्रॉडक्ट की परिभाषा की मदद से एक डिक्शनरी बनाएं.

    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'
         }
    }
    
  4. एक ऐसा फ़ंक्शन बनाएं जो स्क्रिप्ट को कमांड लाइन से चलाए जाने पर चलता हो. यह फ़ंक्शन, Content 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)
    
    
  5. स्क्रिप्ट चलाने और एपीआई कॉल चलाने के लिए, टर्मिनल विंडो से googleads-shopping-samples/python/ पर जाएं और यह चलाएं:

    python -m shopping.content.products.my-insert
    

    अगर कॉल पूरा होता है, तो सेवा, टर्मिनल पर इस मैसेज को प्रिंट करती है: OfferId "offerId" वाला प्रॉडक्ट बनाया गया था.

  6. प्रॉडक्ट जोड़ दिया गया है या नहीं, इसकी पुष्टि करने के लिए products.list तरीके के लिए एपीआई एक्सप्लोरर का इस्तेमाल करें. इससे, आपको अपने Merchant Center खाते में मौजूद सभी प्रॉडक्ट दिखाए जा सकेंगे.

    products.list तरीके के लिए API एक्सप्लोरर में, ये वैल्यू डालें:

    1. अपना merchantId डालें.
    1. क्रेडेंशियल सेक्शन में, Google OAuth 2.0 और एपीआई पासकोड चुनें.
    2. लागू करें बटन पर क्लिक करें.
    3. पूछे जाने पर, अपने Merchant Center खाते से जुड़े Google खाते से साइन इन करें.

    अगर प्रॉडक्ट जोड़ दिया गया था, तो एपीआई एक्सप्लोरर के रिस्पॉन्स में प्रॉडक्ट डेटा दिखता है.

शॉपिंग विज्ञापनों और मुफ़्त में दिखाई जाने वाली लिस्टिंग की नीतियों का पालन करना व्यापारियों/कंपनियों/कारोबारियों की ज़िम्मेदारी है. अगर हमें इन नीतियों का उल्लंघन करने वाला कॉन्टेंट या व्यवहार मिलता है, तो Google Shopping के पास इन नीतियों को लागू करने और सही तरीके से जवाब देने का अधिकार सुरक्षित है.