はじめに
ゼロタッチ登録 API を使用すると、デバイス販売パートナーは統合を自動化できます。 組織のセールスツールにはゼロタッチ登録が組み込まれており、 ユーザー、顧客、生産性が向上しますAPI を使用して、ユーザーが次のことを行えるようにしてください。
- 購入したデバイスをお客様のゼロタッチ登録アカウントに割り当てる。
- お客様のゼロタッチ登録アカウントを作成する。
- 組織の電話番号と注文のメタデータをデバイスに結び付ける。
- お客様に割り当てられたデバイスに関するレポートを作成する。
このドキュメントでは、API を紹介し、パターンについて説明します。目標 確認したい場合は、クイックスタートを Java、 .NET Python。
API のコンセプト
お客様とデバイスは、API で使用するコア リソースです。顧客を作成するには、create
を呼び出します。デバイスを作成できます
クレーム API メソッドを使用します(下記参照)。組織は
ゼロタッチ登録ポータルを使用してお客様とデバイスを作成する
- 顧客
- 組織がデバイスを販売する会社。お客様が
name
とID
を持っている。デバイスを申請または検索する場合は、お客様を使用します。宛先 詳しくは、Customer
をご覧ください。 - デバイス
- 組織でゼロタッチ登録対応の Android または ChromeOS デバイス
考えることができますデバイスにはハードウェア ID、メタデータ、お客様がある
デバイスは API の中心となるため、ほとんどのメソッドで使用します。詳しくは、
Device
をご覧ください。 - DeviceIdentifier
- 製造されたものを識別するために IMEI や MEID などのハードウェア ID をカプセル化します
できます。
DeviceIdentifier
を使用して、検索、更新、または復元するデバイスをターゲットにします。詳しくは、 識別子。 - DeviceMetadata
- デバイスのメタデータの Key-Value ペアを格納します。使用
DeviceMetadata
: 組織のメタデータを保存します。詳しくは、デバイスのメタデータをご覧ください。
アプリで使用できるすべての API メソッドとリソースを一覧表示するには、 API リファレンス。
顧客を作成する
Android デバイスの場合、販売パートナーがお客様を作成する責任があります。 お客様に代わり Google のサービスを 提供しますお客様はこのアカウントを使用してゼロタッチ ポータルにアクセスし、デバイスのプロビジョニング設定を構成します。この手順は、すでに Google Workspace アカウントが プロビジョニング設定の構成に使用する Workspace アカウント。
create
API メソッドを呼び出して、ゼロタッチ登録用のお客様アカウントを作成できます。顧客には
追加する場合、アプリのユーザーは
正しいことを確認します。顧客名の作成後に顧客名を編集することはできません
提供します。
オーナーになるには、Google アカウントに関連付けられた会社のメールアドレスを少なくとも 1 つ含める必要があります。個人の Gmail アカウントは、 APIアカウントの関連付けについてお客様からサポートが求められた場合は、Google アカウントを関連付けるの手順をお送りください。
API を呼び出してお客様を作成した後、お客様は社員のポータル アクセスを管理します。API を使用してお客様のユーザーを編集することはできません。スニペット 顧客の作成方法は次のとおりです。
// Provide the customer data as a Company type.
// The API requires a name and owners.
Company customer = new Company();
customer.setCompanyName("XYZ Corp");
customer.setOwnerEmails(Arrays.asList("liz@example.com", "darcy@example.com"));
customer.setAdminEmails(Collections.singletonList("jane@example.com"));
// Use our reseller ID for the parent resource name.
String parentResource = String.format("partners/%d", PARTNER_ID);
// Call the API to create the customer using the values in the company object.
CreateCustomerRequest body = new CreateCustomerRequest();
body.setCustomer(customer);
Company response = service.partners().customers().create(parentResource, body).execute();
// Provide the customer data as a Company type.
// The API requires a name and owners.
var customer = new Company
{
CompanyName = "XYZ Corp",
OwnerEmails = new String[] { "liz@example.com", "darcy@example.com" },
AdminEmails = new String[] { "jane@example.com" }
};
// Use our reseller ID for the parent resource name.
var parentResource = String.Format("partners/{0}", PartnerId);
// Call the API to create the customer using the values in the company object.
var body = new CreateCustomerRequest
{
Customer = customer
};
var request = service.Partners.Customers.Create(body, parentResource);
var response = request.Execute();
# Provide the customer data as a Company type. The API requires
# a name and at least one owner.
company = {'companyName':'XYZ Corp', \
'ownerEmails':['liz@example.com', 'darcy@example.com'], \
'adminEmails':['jane@example.com']}
# Use our reseller ID for the parent resource name.
parent_resource = 'partners/{0}'.format(PARTNER_ID)
# Call the API to create the customer using the values in the company object.
response = service.partners().customers().create(parent=parent_resource,
body={'customer':company}).execute()
お客様の社員のオーナーロールと管理者ロールについて詳しくは、ポータル ユーザーをご覧ください。
お客様に代わってデバイスを申請する
お客様はデバイスを購入した後、アカウントでデバイスのプロビジョニング設定を構成する必要があります。デバイスの申請でデバイスが追加される ゼロタッチ登録が可能になり、お客様は プロビジョニング設定です
デバイスのプロビジョニング レコードには、ゼロタッチ登録のセクションがあります。デバイスを割り当てるには、お客様のレコードのゼロタッチ登録セクションを申請します。partners.devices.claim
を呼び出すか、
partners.devices.claimAsync
メソッド
議論しますsectionType
の値には常に SECTION_TYPE_ZERO_TOUCH
を指定してください。
お客様のデバイスに対する申し立てを解除(後述)する必要があります。
別のお客様に対して同じデバイスの申請を行う。新しいデバイスを作成するときに、申し立て方法は DeviceIdentifier
フィールド(IMEI または MEID、シリアル番号、メーカー名、モデル、ChromeOS デバイスの認証済みデバイス ID など)を検証します。
以下のスニペットは、デバイスを申請する方法を示しています。
// Identify the device to claim.
DeviceIdentifier identifier = new DeviceIdentifier();
// The manufacturer value is optional but recommended for cellular devices
identifier.setManufacturer("Google");
identifier.setImei("098765432109875");
// Create the body to connect the customer with the device.
ClaimDeviceRequest body = new ClaimDeviceRequest();
body.setDeviceIdentifier(identifier);
body.setCustomerId(customerId);
body.setSectionType("SECTION_TYPE_ZERO_TOUCH");
// Claim the device.
ClaimDeviceResponse response = service.partners().devices().claim(PARTNER_ID, body).execute();
// Identify the device to claim.
var deviceIdentifier = new DeviceIdentifier
{
// The manufacturer value is optional but recommended for cellular devices
Manufacturer = "Google",
Imei = "098765432109875"
};
// Create the body to connect the customer with the device.
ClaimDeviceRequest body = new ClaimDeviceRequest
{
DeviceIdentifier = deviceIdentifier,
CustomerId = CustomerId,
SectionType = "SECTION_TYPE_ZERO_TOUCH"
};
// Claim the device.
var response = service.Partners.Devices.Claim(body, PartnerId).Execute();
# Identify the device to claim.
# The manufacturer value is optional but recommended for cellular devices
device_identifier = {'manufacturer':'Google', 'imei':'098765432109875'}
# Create the body to connect the customer with the device.
request_body = {'deviceIdentifier':device_identifier, \
'customerId':customer_id, \
'sectionType':'SECTION_TYPE_ZERO_TOUCH'}
# Claim the device.
response = service.partners().devices().claim(partnerId=PARTNER_ID,
body=request_body).execute()
デバイスの申し立てを解除する
組織はお客様からのデバイスの申請を解除できます。デバイスの申し立てを解除すると、そのデバイスはゼロタッチ登録から削除されます。販売パートナー様は、
別のアカウントへの移行や返品を希望している、または誤って申し立てが行われた。
メソッド partners.devices.unclaim
または partners.devices.unclaimAsync
を呼び出して、お客様のデバイスの申し立てを取り消します。
ベンダー
ベンダーを使用して、ディーラー ネットワーク(地域のディーラー)での販売パートナーを表すことができます。 または販売パートナーのネットワーク、または ユーザーの代わりに デバイスを保護できますベンダーは、ユーザー、顧客、 デバイス:
- 作成したベンダーは、ゼロタッチ登録のアカウントや各ベンダーの 共有します。
- ベンダーのお客様とデバイスを表示し、ベンダーのデバイスの登録を解除できます。ただし、ベンダーのお客様にデバイスを割り当てることはできません。
ポータルを使用して組織のベンダーを作成します。API は使用できません。新しいベンダーを作成するには、アカウントのロールがオーナーである必要があります。組織にベンダーがいる場合は
partners.vendors.list
を呼び出して、
ベンダーおよび partners.vendors.customers.list
ベンダーの顧客を獲得することです次の例では、これらのメソッドの両方を使用して、ベンダーの顧客の利用規約のステータスを含むレポートを印刷します。
// First, get the organization's vendors.
String parentResource = String.format("partners/%d", PARTNER_ID);
ListVendorsResponse results = service.partners().vendors().list(parentResource).execute();
if (results.getVendors() == null) {
return;
}
// For each vendor, report the company name and a maximum 5 customers.
for (Company vendor: results.getVendors()) {
System.out.format("\n%s customers\n", vendor.getCompanyName());
System.out.println("---");
// Use the vendor's API resource name as the parent resource.
AndroidProvisioningPartner.Partners.Vendors.Customers.List customerRequest =
service.partners().vendors().customers().list(vendor.getName());
customerRequest.setPageSize(5);
ListVendorCustomersResponse customerResponse = customerRequest.execute();
List<Company> customers = customerResponse.getCustomers();
if (customers == null) {
System.out.println("No customers");
break;
} else {
for (Company customer: customers) {
System.out.format("%s: %s\n",
customer.getCompanyName(),
customer.getTermsStatus());
}
}
}
// First, get the organization's vendors.
var parentResource = String.Format("partners/{0}", PartnerId);
var results = service.Partners.Vendors.List(parentResource).Execute();
if (results.Vendors == null)
{
return;
}
// For each vendor, report the company name and a maximum 5 customers.
foreach (Company vendor in results.Vendors)
{
Console.WriteLine("\n{0} customers", vendor);
Console.WriteLine("---");
// Use the vendor's API resource name as the parent resource.
PartnersResource.VendorsResource.CustomersResource.ListRequest customerRequest =
service.Partners.Vendors.Customers.List(vendor.Name);
customerRequest.PageSize = 5;
var customerResponse = customerRequest.Execute();
IList<Company> customers = customerResponse.Customers;
if (customers == null)
{
Console.WriteLine("No customers");
break;
}
else
{
foreach (Company customer in customers)
{
Console.WriteLine("{0}: {1}", customer.Name, customer.TermsStatus);
}
}
}
# First, get the organization's vendors.
parent_resource = 'partners/{0}'.format(PARTNER_ID)
vendor_response = service.partners().vendors().list(
parent=parent_resource).execute()
if 'vendors' not in vendor_response:
return
# For each vendor, report the company name and a maximum 5 customers.
for vendor in vendor_response['vendors']:
print '\n{0} customers'.format(vendor['companyName'])
print '---'
# Use the vendor's API resource name as the parent resource.
customer_response = service.partners().vendors().customers().list(
parent=vendor['name'], pageSize=5).execute()
if 'customers' not in customer_response:
print 'No customers'
break
for customer in customer_response['customers']:
print ' {0}: {1}'.format(customer['name'], customer['termsStatus'])
デバイスのコレクションがある場合は、
ベンダーがデバイスを申請しました。数値のリセラー ID を取得するには、デバイスの申し立てレコードの resellerId
フィールドの値を調べます。
組織は、ベンダーが申請したデバイスの申請を解除できます。デバイスを変更する他の API 呼び出しでは、API メソッドを呼び出す前に、組織がデバイスを申し立てていることを確認する必要があります。次の例は、その方法を示しています。
// Get the devices claimed for two customers: one of our organization's
// customers and one of our vendor's customers.
FindDevicesByOwnerRequest body = new FindDevicesByOwnerRequest();
body.setSectionType("SECTION_TYPE_ZERO_TOUCH");
body.setCustomerId(Arrays.asList(resellerCustomerId, vendorCustomerId));
body.setLimit(MAX_PAGE_SIZE);
FindDevicesByOwnerResponse response =
service.partners().devices().findByOwner(PARTNER_ID, body).execute();
if (response.getDevices() == null) {
return;
}
for (Device device: response.getDevices()) {
// Confirm the device was claimed by our reseller and not a vendor before
// updating metadata in another method.
for (DeviceClaim claim: device.getClaims()) {
if (claim.getResellerId() == PARTNER_ID) {
updateDeviceMetadata(device.getDeviceId());
break;
}
}
}
// Get the devices claimed for two customers: one of our organization's
// customers and one of our vendor's customers.
FindDevicesByOwnerRequest body = new FindDevicesByOwnerRequest
{
Limit = MaxPageSize,
SectionType = "SECTION_TYPE_ZERO_TOUCH",
CustomerId = new List<long?>
{
resellerCustomerId,
vendorCustomerId
}
};
var response = service.Partners.Devices.FindByOwner(body, PartnerId).Execute();
if (response.Devices == null)
{
return;
}
foreach (Device device in response.Devices)
{
// Confirm the device was claimed by our reseller and not a vendor before
// updating metadata in another method.
foreach (DeviceClaim claim in device.Claims)
{
if (claim.ResellerId == PartnerId)
{
UpdateDeviceMetadata(device.DeviceId);
break;
}
}
}
# Get the devices claimed for two customers: one of our organization's
# customers and one of our vendor's customers.
request_body = {'limit':MAX_PAGE_SIZE, \
'pageToken':None, \
'customerId':[reseller_customer_id, vendor_customer_id], \
'sectionType':'SECTION_TYPE_ZERO_TOUCH'}
response = service.partners().devices().findByOwner(partnerId=PARTNER_ID,
body=request_body).execute()
for device in response['devices']:
# Confirm the device was claimed by our reseller and not a vendor before
# updating metadata in another method.
for claim in device['claims']:
if claim['resellerId'] == PARTNER_ID:
update_device_metadata(device['deviceId'])
break
長時間実行バッチ オペレーション
この API には、デバイス メソッドの非同期バージョンが含まれています。
これらの方法を使用すると、多くのデバイスをバッチ処理できます。また、同期処理が
メソッドは、API リクエストごとに 1 台のデバイスを処理します。非同期メソッド名には Async という接尾辞が付いています(例: claimAsync
)。
非同期 API メソッドは、処理が完了する前に結果を返します。非同期メソッドを使用すると、長時間実行オペレーションの完了を待機している間も、アプリ(またはツール)がユーザーに対して応答性を維持できます。アプリは オペレーションのステータスを定期的にチェックします。
運用
Operation
を使用して、長時間実行バッチ オペレーションを追跡します。非同期メソッドの呼び出しが成功すると、レスポンスでオペレーションへの参照が返されます。以下の JSON スニペットは、呼び出し後の一般的なレスポンスを示しています。
updateMetadataAsync
:
{
"name": "operations/apibatchoperation/1234567890123476789"
}
各オペレーションには、個々のタスクのリストが含まれています。発信
operations.get
: ステータスに関する情報を確認し、
結果を返すことができます。次のスニペットは、その方法を示しています。独自のアプリでは、エラーを処理する必要があります。
// Build out the request body to apply the same order number to a customer's
// purchase of 2 devices.
UpdateMetadataArguments firstUpdate = new UpdateMetadataArguments();
firstUpdate.setDeviceMetadata(metadata);
firstUpdate.setDeviceId(firstTargetDeviceId);
UpdateMetadataArguments secondUpdate = new UpdateMetadataArguments();
secondUpdate.setDeviceMetadata(metadata);
secondUpdate.setDeviceId(firstTargetDeviceId);
// Start the device metadata update.
UpdateDeviceMetadataInBatchRequest body = new UpdateDeviceMetadataInBatchRequest();
body.setUpdates(Arrays.asList(firstUpdate, secondUpdate));
Operation response = service
.partners()
.devices()
.updateMetadataAsync(PARTNER_ID, body)
.execute();
// Assume the metadata update started, so get the Operation for the update.
Operation operation = service.operations().get(response.getName()).execute();
// Build out the request body to apply the same order number to a customer's
// purchase of 2 devices.
var updates = new List<UpdateMetadataArguments>
{
new UpdateMetadataArguments
{
DeviceMetadata = metadata,
DeviceId = firstTargetDeviceId
},
new UpdateMetadataArguments
{
DeviceMetadata = metadata,
DeviceId = secondTargetDeviceId
}
};
// Start the device metadata update.
UpdateDeviceMetadataInBatchRequest body = new UpdateDeviceMetadataInBatchRequest
{
Updates = updates
};
var response = service.Partners.Devices.UpdateMetadataAsync(body, PartnerId).Execute();
// Assume the metadata update started, so get the Operation for the update.
Operation operation = service.Operations.Get(response.Name).Execute();
# Build out the request body to apply the same order number to a customer's
# purchase of 2 devices.
updates = [{'deviceMetadata':metadata,'deviceId':first_target_device_id},
{'deviceMetadata':metadata,'deviceId':second_target_device_id}]
# Start the device metadata update.
response = service.partners().devices().updateMetadataAsync(
partnerId=PARTNER_ID, body={'updates':updates}).execute()
# Assume the metadata update started, so get the Operation for the update.
operation = service.operations().get(name=response['name']).execute()
オペレーションが完了したかどうかを確認するには、値が true
の done
フィールドがオペレーションにあるかどうかを確認します。done
がないか false
の場合、オペレーションはまだ実行中です。
レスポンス
オペレーションが完了すると、API は個々のタスクのすべてまたはいずれも成功しなかった場合でも、結果でオペレーションを更新します。response
フィールドは、オペレーション内の各デバイスの処理を詳細に記述した DevicesLongRunningOperationResponse
オブジェクトです。
successCount
フィールドを調べて、失敗したタスクがあるかどうかを効率的に調べる
大規模な結果リストを反復処理する必要はありませんDevicesLongRunningOperationResponse
の perDeviceStatus
フィールドは、オペレーション内の各デバイスの詳細を示す OperationPerDevice
インスタンスのリストです。リストの順序は、元のリクエストのタスクと一致します。
各 OperationPerDevice
タスクには、result
フィールドと、サーバーが受信したリクエストのリマインダーの概要が含まれています。タスクが成功したか失敗したかを確認する
result
フィールドを使用します。
以下の JSON スニペットは、API 呼び出し後のオペレーションからの一般的なレスポンスの一部を示しています。
updateMetadataAsync
への呼び出し:
"response": {
"perDeviceStatus": [
{
"result": {
"deviceId": "12345678901234567",
"status": "SINGLE_DEVICE_STATUS_SUCCESS"
},
"updateMetadata": {
"deviceId": "12345678901234567",
"deviceMetadata": {
"entries": {
"phonenumber": "+1 (800) 555-0100"
}
}
}
}
],
"successCount": 1
}
進捗状況を管理する
アプリで進捗状況を追跡する必要がある場合は、
あります。metadata
フィールドには、実行中のオペレーションの最新の進行状況を確認するためにアプリが使用する DevicesLongRunningOperationMetadata
インスタンスが含まれています。次の表に示す DevicesLongRunningOperationMetadata
のフィールドを使用して、オペレーションの進行状況を追跡します。
フィールド | 一般的な使用法 |
---|---|
processingStatus
|
オペレーションの進行に伴い、BATCH_PROCESS_PENDING から BATCH_PROCESS_IN_PROGRESS に変わり、その後 BATCH_PROCESS_PROCESSED に変わります。 |
progress
|
処理された更新の割合。アプリはこの情報を使用して、終了時間を推定できます。progress が
オペレーションの最中に 100 にすることもできますが、
オペレーションの done フィールドを調べて、
結果があります |
devicesCount
|
オペレーション内の更新数を示します。API が一部の更新を解析できない場合、この数はリクエスト内の更新数と異なる場合があります。 |
以下のシンプルな例は、アプリが進行状況のメタデータを使用して以下の操作を行う方法を示しています。 ポーリング間隔を設定できます。アプリで、より高度なタスクが必要になる場合がある ランナーを使用します。また、エラー処理も追加する必要があります。
// Milliseconds between polling the API.
private static long MIN_INTERVAL = 2000;
private static long MAX_INTERVAL = 10000;
// ...
// Start the device metadata update.
Operation response = service
.partners()
.devices()
.updateMetadataAsync(PARTNER_ID, body)
.execute();
String operationName = response.getName();
// Start polling for completion.
long startTime = new Date().getTime();
while (true) {
// Get the latest update on the operation's progress using the API.
Operation operation = service.operations().get(operationName).execute();
if (operation.get("done") != null && operation.getDone()) {
// The operation is finished. Print the status.
System.out.format("Operation complete: %s of %s successful device updates\n",
operation.getResponse().get("successCount"),
operation.getMetadata().get("devicesCount"));
break;
} else {
// Estimate how long the operation *should* take - within min and max value.
BigDecimal opProgress = (BigDecimal) operation.getMetadata().get("progress");
double progress = opProgress.longValue();
long interval = MAX_INTERVAL;
if (progress > 0) {
interval = (long) ((new Date().getTime() - startTime) *
((100.0 - progress) / progress));
}
interval = Math.max(MIN_INTERVAL, Math.min(interval, MAX_INTERVAL));
// Sleep until the operation should be complete.
Thread.sleep(interval);
}
}
// Milliseconds between polling the API.
private static double MinInterval = 2000;
private static double MaxInterval = 10000;
// ...
// Start the device metadata update.
var response = service.Partners.Devices.UpdateMetadataAsync(body, PartnerId).Execute();
var operationName = response.Name;
// Start polling for completion.
var startTime = DateTime.Now;
while (true)
{
// Get the latest update on the operation's progress using the API.
Operation operation = service.Operations.Get(operationName).Execute();
if (operation.Done == true)
{
// The operation is finished. Print the status.
Console.WriteLine("Operation complete: {0} of {1} successful device updates",
operation.Response["successCount"],
operation.Metadata["devicesCount"]);
break;
}
else
{
// Estimate how long the operation *should* take - within min and max value.
double progress = (double)(long)operation.Metadata["progress"];
double interval = MaxInterval;
if (progress > 0)
{
interval = DateTime.Now.Subtract(startTime).TotalMilliseconds *
((100.0 - progress) / progress);
}
interval = Math.Max(MinInterval, Math.Min(interval, MaxInterval));
// Sleep until the operation should be complete.
System.Threading.Thread.Sleep((int)interval);
}
}
# Seconds between polling the API.
MIN_INTERVAL = 2;
MAX_INTERVAL = 10;
# ...
# Start the device metadata update
response = service.partners().devices().updateMetadataAsync(
partnerId=PARTNER_ID, body={'updates':updates}).execute()
op_name = response['name']
start_time = time.time()
# Start polling for completion
while True:
# Get the latest update on the operation's progress using the API
op = service.operations().get(name=op_name).execute()
if 'done' in op and op['done']:
# The operation is finished. Print the status.
print('Operation complete: {0} of {1} successful device updates'.format(
op['response']['successCount'], op['metadata']['devicesCount']
))
break
else:
# Estimate how long the operation *should* take - within min and max.
progress = op['metadata']['progress']
interval = MIN_INTERVAL
if progress > 0:
interval = (time.time() - start_time) * ((100.0 - progress) / progress)
interval = max(MIN_INTERVAL, min(interval, MAX_INTERVAL))
# Sleep until the operation should be complete.
time.sleep(interval)
アプリのユーザーに適したポーリング方法を選択してください。一部のアプリユーザー 定期的な進捗状況の更新が有益となる場合があります できます。
ページングされた結果
partners.devices.findByOwner
API メソッドは、非常に大きなデバイスのリストを返すことがあります。レスポンスのサイズを小さくするために、
他の API メソッド(
partners.devices.findByIdentifier
)
サポートしています。ページングされた結果を使用すると、アプリケーションは
一度に 1 ページずつリクエスト、処理できます。
API メソッドを呼び出した後、レスポンスに nextPageToken
の値が含まれているかどうかを確認します。nextPageToken
が null
でない場合、アプリはメソッドを再度呼び出して、デバイスの別のページを取得できます。limit
パラメータでデバイス数の上限を設定する必要があります。nextPageToken
が null
の場合、アプリは
最後のページです
以下のメソッド例は、アプリがデバイスのリストを出力する方法を示しています。 ページごとに次の操作を行います。
private static long MAX_PAGE_SIZE = 10;
// ...
/**
* Demonstrates how to loop through paginated lists of devices.
* @param pageToken The token specifying which result page to return.
* @throws IOException If the zero-touch API call fails.
*/
private void printDevices(String pageToken) throws IOException {
// Create the request body to find the customer's devices.
FindDevicesByOwnerRequest body = new FindDevicesByOwnerRequest();
body.setLimit(MAX_PAGE_SIZE);
body.setSectionType("SECTION_TYPE_ZERO_TOUCH");
body.setCustomerId(Collections.singletonList(targetCustomerId));
// Call the API to get a page of Devices. Send a page token from the method
// argument (might be None). If the page token is None, the API returns the first page.
FindDevicesByOwnerResponse response =
service.partners().devices().findByOwner(PARTNER_ID, body).execute();
if (response.getDevices() == null) {
return;
}
// Print the devices included in this page of results.
for (Device device: response.getDevices()) {
System.out.format("Device %s\n", device.getName());
}
System.out.println("---");
// Check to see if another page of devices is available. If yes,
// fetch and print the devices.
if (response.getNextPageToken() != null) {
this.printDevices(response.getNextPageToken());
}
}
// ...
// Pass null to start printing the first page of devices.
printDevices(null);
private static int MaxPageSize = 10;
// ...
/// <summary>Demonstrates how to loop through paginated lists of devices.</summary>
/// <param name="pageToken">The token specifying which result page to return.</param>
private void PrintDevices(string pageToken)
{
// Create the request body to find the customer's devices.
FindDevicesByOwnerRequest body = new FindDevicesByOwnerRequest
{
PageToken = pageToken,
Limit = MaxPageSize,
SectionType = "SECTION_TYPE_ZERO_TOUCH",
CustomerId = new List<long?>
{
targetCustomerId
}
};
// Call the API to get a page of Devices. Send a page token from the method
// argument (might be None). If the page token is None, the API returns the first page.
var response = service.Partners.Devices.FindByOwner(body, PartnerId).Execute();
if (response.Devices == null)
{
return;
}
// Print the devices included in this page of results.
foreach (Device device in response.Devices)
{
Console.WriteLine("Device: {0}", device.Name);
}
Console.WriteLine("---");
// Check to see if another page of devices is available. If yes,
// fetch and print the devices.
if (response.NextPageToken != null)
{
this.PrintDevices(response.NextPageToken);
}
}
// ...
// Pass null to start printing the first page of devices.
PrintDevices(null);
MAX_PAGE_SIZE = 10;
# ...
def print_devices(page_token):
"""Demonstrates how to loop through paginated lists of devices.
Args:
page_token: The token specifying which result page to return.
"""
# Create the body to find the customer's devices.
request_body = {'limit':MAX_PAGE_SIZE, \
'pageToken':page_token, \
'customerId':[target_customer_id], \
'sectionType':'SECTION_TYPE_ZERO_TOUCH'}
# Call the API to get a page of Devices. Send a page token from the method
# argument (might be None). If the page token is None,
# the API returns the first page.
response = service.partners().devices().findByOwner(partnerId=PARTNER_ID,
body=request_body).execute()
# Print the devices included in this page of results.
for device in response['devices']:
print 'Device: {0}'.format(device['name'])
print '---'
# Check to see if another page of devices is available. If yes,
# fetch and print the devices.
if 'nextPageToken' in response:
print_devices(response['nextPageToken'])
# ...
# Pass None to start printing the first page of devices.
print_devices(None);
次のステップ
API の仕組みがわかったところで、クイックスタート ガイドで例を Java、 .NET Python。Colab を使用して、API 呼び出しの例を確認し、API の呼び出しを自分で試すことができます。