리셀러를 위한 Python 빠른 시작

이 빠른 시작 가이드의 단계를 따르면 약 10분 만에 제로터치에 요청을 보내는 간단한 Python 명령줄 앱 등록 리셀러 API

기본 요건

이 빠른 시작을 실행하려면 다음이 필요합니다.

  • 제로터치 등록 리셀러의 Google 계정 있습니다. 아직 온보딩하지 않은 경우 다음 시작하기 단계를 따르세요. 리셀러 포털 가이드를 참조하세요.
  • Python 2.6 이상
  • pip 패키지 관리 있습니다.
  • 인터넷 및 웹브라우저 액세스

1단계: 제로터치 등록 API 사용 설정하기

  1. 다음을 사용하세요. 마법사를 사용하여 Google Developers Console에서 프로젝트를 만들거나 선택하고 API를 자동으로 사용 설정합니다 계속을 클릭한 후 사용자 인증 정보로 이동을 클릭합니다. 를 참고하세요.
  2. 어떤 데이터에 액세스하게 되나요?애플리케이션 데이터로 설정합니다.
  3. 다음을 클릭합니다. 서비스를 만들라는 메시지가 표시됩니다. 있습니다.
  4. 서비스 계정 이름을 설명하는 이름을 지정합니다.
  5. 서비스 계정 ID (이메일 주소처럼 보임)를 적어 둡니다. 나중에 사용할 수 있습니다
  6. 역할서비스 계정 > 서비스 계정 사용자.
  7. 완료를 클릭하여 서비스 계정 만들기를 마칩니다.
  8. 만든 서비스 계정의 이메일 주소를 클릭합니다.
  9. **키**를 클릭합니다.
  10. **키 추가**를 클릭한 다음 **새 키 만들기**를 클릭합니다.
  11. **키 유형**에서 **JSON**을 선택합니다.
  12. 만들기를 클릭하면 비공개 키가 컴퓨터에 다운로드됩니다.
  13. **닫기**를 클릭합니다.
  14. 파일을 작업 디렉터리로 이동하고 이름을 service_account_key.json로 바꿉니다.
  1. 제로터치 등록 포털을 엽니다. 로그인해야 할 수도 있습니다.
  2. 서비스를 클릭합니다. 계정
  3. 서비스 계정 연결을 클릭합니다.
  4. 이메일 주소를 이전에 만든 서비스 계정의 주소로 설정합니다.
  5. 제로터치에서 서비스 계정을 사용하려면 서비스 계정 연결을 클릭합니다. 등록 계정

3단계: Google 클라이언트 라이브러리 설치

다음 명령어를 실행하여 pip를 사용하여 라이브러리를 설치합니다.

pip install --upgrade google-api-python-client

라이브러리의 설치 다른 설치 페이지를 참조하세요. 있습니다.

4단계: 샘플 설정

작업 디렉터리에 quickstart.py라는 파일을 만듭니다. 파일을 저장합니다. 자체 리셀러 파트너 삽입 IDPARTNER_ID( 합니다.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Zero-touch enrollment reseller quickstart.

This script forms the quickstart introduction to the zero-touch enrollemnt
reseller API. To learn more, visit https://developer.google.com/zero-touch
"""

from apiclient.discovery import build
from httplib2 import Http
from oauth2client.service_account import ServiceAccountCredentials

# TODO: replace this with your partner reseller ID.
PARTNER_ID = '11036885';

# A single auth scope is used for the zero-touch enrollment customer API.
SCOPES = ['https://www.googleapis.com/auth/androidworkprovisioning']
SERVICE_ACCOUNT_KEY_FILE = 'service_account_key.json'

def get_credential():
  """Creates a Credential object with the correct OAuth2 authorization.

  Creates a Credential object with the correct OAuth2 authorization
  for the service account that calls the reseller API. The service
  endpoint calls this method when setting up a new service instance.

  Returns:
    Credential, the user's credential.
  """
  credential = ServiceAccountCredentials.from_json_keyfile_name(
      SERVICE_ACCOUNT_KEY_FILE, scopes=SCOPES)
  return credential


def get_service():
  """Creates a service endpoint for the zero-touch enrollment reseller API.

  Builds and returns an authorized API client service for v1 of the API. Use
  the service endpoint to call the API methods.

  Returns:
    A service Resource object with methods for interacting with the service.
  """
  http_auth = get_credential().authorize(Http())
  service = build('androiddeviceprovisioning', 'v1', http=http_auth)
  return service


def main():
  """Runs the zero-touch enrollment quickstart app.
  """
  # Create a zero-touch enrollment API service endpoint.
  service = get_service()

  # Send an API request to list all our customers.
  response = service.partners().customers().list(partnerId=PARTNER_ID).execute()

  # Print out the details of each customer.
  if 'customers' in response:
    for customer in response['customers']:
      print 'Name:{0}  ID:{1}'.format(
          customer['companyName'], customer['companyId'])
  else:
    print 'No customers found'


if __name__ == '__main__':
  main()

파트너 ID

API 호출에는 일반적으로 리셀러 파트너 ID가 인수로 필요합니다. 제로터치 등록 포털에서 파트너 ID를 삭제하려면 다음 단계를 따르세요.

  1. 포털을 엽니다. 로그인해야 할 수도 있습니다.
  2. 서비스를 클릭합니다. 계정
  3. 리셀러 ID 줄에서 파트너 ID 번호를 복사합니다.

5단계: 샘플 실행

운영체제의 도움말을 사용하여 파일에서 스크립트를 실행합니다. UNIX 및 Mac에서 터미널에서 아래 명령어를 실행합니다.

python quickstart.py

API 응답 인쇄

API를 사용해 볼 때 응답을 더 쉽게 검사할 수 있도록 JSON 형식을 지정합니다. 응답 데이터를 반환합니다. 아래 스니펫은 JSON 모듈:

from json import dumps

# ...

results = provisioning.partners().devices().claimAsync(partnerId=MY_PARTNER_ID,
 body={'claims':new_claims}).execute()
# Print formatted JSON response
print dumps(results, indent=4, sort_keys=True)

문제 해결

빠른 시작에서 어떤 문제가 발생했는지 알려주시면 최선을 다해 도와드리겠습니다. 수정할 수 있습니다 제로터치에서 서비스 계정을 사용하여 API 호출을 승인하는 방법을 알아보려면 승인.

자세히 알아보기