API 호출

googleads/googleads-shopping-samples GitHub의 저장소에는 각 클라이언트의 일반적인 작업을 위한 샘플 코드가 포함되어 있습니다. 있습니다. 예를 들어 googleads-shopping-samples/python/shopping/content/products/에서 코드 제공 일반적인 작업을 위한 products 살펴보겠습니다 이 가이드에서는 빈 파일로 시작하여 새 제품을 삽입하는 예를 보여주면 애플리케이션 구성 및 필수 구성 요소를 Content API 최종 결과는 products/insert.py 샘플 파일을 참조하세요. 그런 다음 API 탐색기 products.list 메서드에 의해 제품이 성공적으로 추가되었는지 확인합니다.

첫 번째 전화를 걸려면 다음 단계를 완료하세요.

  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
    

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

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

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

    1. merchantId을(를) 입력하세요.
    를 통해 개인정보처리방침을 정의할 수 있습니다.
    1. 사용자 인증 정보 섹션에서 Google OAuth 2.0API 키를 선택합니다.
    2. 실행 버튼을 클릭합니다.
    3. 메시지가 표시되면 판매자와 연결된 Google 계정으로 로그인합니다. 센터 계정을 탭합니다.

    제품이 성공적으로 추가된 경우 제품 데이터가 API에 표시됩니다. 알 수 있습니다.

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