はじめに
ゼロタッチ登録 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 メソッドを呼び出して、作成を行うことができます。
ゼロタッチ登録の顧客アカウントを作成する。顧客には
追加する場合、アプリのユーザーは
正しいことを確認します。顧客名の作成後に顧客名を編集することはできません
提供します。
少なくとも 1 つの会社のメールアドレスを含める必要があります。 所有者となる Google アカウント。個人の Gmail アカウントは、 APIアカウントの関連付けについてお客様からお問い合わせを受けた場合は、 手順: Google アカウントを関連付ける
API を呼び出して顧客を作成すると、その顧客がその顧客の 顧客情報を編集することはできません。API を使用するユーザーですスニペット 顧客の作成方法は次のとおりです。
Java
// 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();
.NET
// 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();
Python
# 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
メソッド
議論します次の要素の値として常に SECTION_TYPE_ZERO_TOUCH
を指定します。
sectionType
。
お客様のデバイスに対する申し立てを解除(後述)する必要があります。
別のお客様に対して同じデバイスの申請を行う。クレームのメソッド
DeviceIdentifier
フィールドを検証する
(IMEI や MEID、シリアル番号など)は、
メーカー名とモデル、
新しいデバイスの作成時に、ChromeOS デバイスの認証済みデバイス ID になります。
以下のスニペットは、デバイスを申請する方法を示しています。
Java
// 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();
.NET
// 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();
Python
# 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 を使用できません。アカウントの役割は、
Owner: 新しいベンダーを作成します。組織にベンダーがいる場合は
partners.vendors.list
を呼び出して、
ベンダーおよび partners.vendors.customers.list
ベンダーの顧客を獲得することです次の例では、この両方の方法を使用しています
ベンダーの利用規約のステータスを示すレポートを印刷する
顧客:
Java
// 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()); } } }
.NET
// 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); } } }
Python
# 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 メソッドを呼び出します次の例はその方法を示しています。
Java
// 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; } } }
.NET
// 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; } } }
Python
# 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
: ステータスに関する情報を確認し、
結果を返すことができます。以下のスニペットは、
可能性があります。実際のアプリでは、エラーを処理する必要があります。
Java
// 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();
.NET
// 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();
Python
# 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()
オペレーションが完了したかどうかを確認するには、オペレーションの done
フィールドを確認します。
値は true
です。done
が存在しないか false
の場合でも、オペレーションは継続されます。
できます。
レスポンス
オペレーションが終了すると、API は結果を使用してオペレーションを更新します。
タスクが成功するか 1 つも成功しない場合のレスポンスが向上します。response
フィールドは、
DevicesLongRunningOperationResponse
オペレーションにおける各デバイスの処理を詳述するオブジェクトです。
successCount
フィールドを調べて、失敗したタスクがあるかどうかを効率的に調べる
大規模な結果リストを反復処理する必要はありませんperDeviceStatus
フィールド:
DevicesLongRunningOperationResponse
は、
各デバイスの詳細を示す 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 が一部の更新を解析できない場合にこのリクエストを再試行します。 |
以下のシンプルな例は、アプリが進行状況のメタデータを使用して以下の操作を行う方法を示しています。 ポーリング間隔を設定できます。アプリで、より高度なタスクが必要になる場合がある ランナーを使用します。また、エラー処理を追加する必要があります。
Java
// 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); } }
.NET
// 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); } }
Python
# 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
の場合、アプリは
最後のページです
以下のメソッド例は、アプリがデバイスのリストを出力する方法を示しています。 ページごとに次の操作を行います。
Java
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);
.NET
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);
Python
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);