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
    

    호출이 성공하면 서비스에서 다음 메시지를 터미널에 출력합니다. Product with offerId "offerId"가 생성되었습니다.

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

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

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

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

판매자는 쇼핑 광고무료 등록정보 정책을 준수해야 합니다. Google 쇼핑은 이러한 정책을 시행하고 이러한 정책을 위반하는 콘텐츠나 행위를 발견하는 경우 적절하게 대응할 권리를 보유합니다.