API 호출

GitHub의 googleads/googleads-shopping-samples 저장소에는 각 클라이언트 라이브러리의 일반 작업을 위한 샘플 코드가 있습니다. 예를 들어 googleads-shopping-samples/python/shopping/content/products/의 샘플은 Python에서 products 리소스를 사용하여 일반적인 작업을 위한 코드를 제공합니다. 이 가이드에서는 빈 파일로 시작하고 새 제품을 삽입하는 예시를 빌드하므로 Content API와 통합되는 애플리케이션의 기본 구조 및 필수 구성요소를 확인할 수 있습니다. 최종 결과는 products/insert.py 샘플 파일의 예와 유사합니다. 그런 다음 products.list 메서드에 API 탐색기를 사용하여 제품이 성공적으로 추가되었는지 확인할 수 있습니다.

처음으로 전화를 걸려면 다음 단계를 완료하세요.

  1. googleads-shopping-samples/python/shopping/content/products/ 디렉터리에서 빈 my-insert.py 파일을 만듭니다. 다음 단계의 모든 코드를 이 파일에 추가합니다.

  2. 필수 모듈의 import 문을 추가합니다.

    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. 제품 고유 ID를 정의하고 제품 정의로 사전을 만듭니다.

    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와 상호작용하도록 서비스 객체를 구성하고, 구성 파일에서 판매자 ID를 가져오고, 요청을 구성하고, 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. 스크립트를 실행하고 API 호출을 실행하려면 터미널 창에서 googleads-shopping-samples/python/로 이동하여 다음을 실행합니다.

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

    호출이 성공하면 서비스는 터미널에 다음 메시지를 출력합니다. ProductId가 'offerId'인 제품이 생성되었습니다.

  6. 제품이 성공적으로 추가되었는지 확인하려면 products.list 메서드에 API 탐색기를 사용하여 판매자 센터 계정의 모든 제품을 반환합니다.

    products.list 메서드의 API 탐색기에 다음 값을 입력합니다.

    1. merchantId을 입력합니다.
    1. 사용자 인증 정보 섹션에서 Google OAuth 2.0API 키를 선택합니다.
    2. 실행 버튼을 클릭합니다.
    3. 메시지가 표시되면 판매자 센터 계정과 연결된 Google 계정으로 로그인합니다.

    제품이 성공적으로 추가되면 제품 데이터가 API 탐색기 응답에 표시됩니다.

판매자는 쇼핑 광고무료 등록정보 정책을 준수해야 할 책임이 있습니다. Google 쇼핑은 이러한 정책을 시행하고 정책을 위반하는 콘텐츠나 행동을 발견하면 적절한 조치를 취할 권리를 보유합니다.