販売パートナー様向け Python クイックスタート

このクイックスタート ガイドの手順に沿って操作してください。10 分ほどで ゼロタッチにリクエストを送信する簡単な Python コマンドライン アプリ 登録販売パートナー API。

前提条件

このクイックスタートを実行するには、次のものが必要です。

  • Google アカウント(ゼロタッチ登録販売パートナーのメンバー) あります。まだオンボーディングしていない場合は、 販売パートナー ポータル ガイドをご覧ください。
  • Python 2.6 以降。
  • pip パッケージ管理 ツールです。
  • インターネット アクセスとウェブブラウザ。

ステップ 1: ゼロタッチ登録 API を有効にする

  1. こちらの ウィザードを使用して、Google Developers Console でプロジェクトを作成または選択し、 API が自動的に有効になります。[続行] をクリックし、[認証情報に進む] をクリックします。
  2. [What data will you be access?] を [Application data] に設定します。
  3. [次へ] をクリックします。サービス アカウントを作成するように求められ、 あります。
  4. [サービス アカウント名] にわかりやすい名前を付けます。
  5. この後の作業で使用するため、サービス アカウント ID(メールアドレスのようなもの)を控えておきましょう。 後で使用します。
  6. [Role] を [Service Accounts >] に設定します。サービス アカウント ユーザー
  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 を レスポンスデータを返します。以下のスニペットは、Python で 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 呼び出しを承認する方法については、 承認

その他の情報