यह कैसे काम करता है

परिचय

ज़ीरो-टच रजिस्ट्रेशन एपीआई की मदद से, डिवाइस रीसेलर अपने इंटिग्रेशन को ऑटोमेट कर सकते हैं. आपके संगठन के सेल्स टूल, ज़ीरो-टच रजिस्ट्रेशन की सुविधा को बेहतर बना सकते हैं—जिससे आपका और आपके ग्राहक भी ज़्यादा बेहतर काम कर सकते हैं. अपने उपयोगकर्ताओं की मदद करने के लिए, एपीआई का इस्तेमाल करें:

  • किसी ग्राहक के 'पहले से तैयार डिवाइस' सुविधा वाले खाते के लिए, खरीदे गए डिवाइस असाइन करें.
  • अपने ग्राहक के लिए, 'पहले से तैयार डिवाइस' सुविधा वाला खाता बनाएं.
  • अपने संगठन का टेलीफ़ोन नंबर अटैच करें और डिवाइसों से मेटाडेटा ऑर्डर करें.
  • अपने ग्राहकों को असाइन किए गए डिवाइसों के बारे में रिपोर्ट बनाएं.

इस दस्तावेज़ में एपीआई के बारे में जानकारी दी गई है. साथ ही, पैटर्न के बारे में भी बताया गया है. अगर आपको एपीआई को खुद एक्सप्लोर करें, Java, .NET या Python.

एपीआई के सिद्धांत

ग्राहक और डिवाइस, एपीआई में इस्तेमाल किए जाने वाले मुख्य संसाधन होते हैं. बनाने के लिए ग्राहक, create पर कॉल करें. आपके पास डिवाइस बनाने का विकल्प है दावा एपीआई के तरीकों का इस्तेमाल करके (नीचे देखें). आपका संगठन ये काम भी कर सकता है: ज़ीरो-टच रजिस्ट्रेशन की सुविधा वाले पोर्टल का इस्तेमाल करके, ग्राहक और डिवाइस बनाएं.

डिवाइस और ग्राहक संसाधन संबंध

ग्राहक
वे कंपनियां जिन्हें आपका संगठन डिवाइस बेचता है. ग्राहकों के पास name है और एक ID. किसी ग्राहक के डिवाइसों पर दावा करने या उन्हें ढूंढने के लिए, उसका इस्तेमाल करें. यहां की यात्रा पर हूं ज़्यादा जानने के लिए, Customer देखें.
डिवाइस
आपके संगठन का, ज़ीरो-टच रजिस्ट्रेशन की सुविधा वाला Android या ChromeOS डिवाइस किसी ग्राहक को बेचता है. डिवाइसों के हार्डवेयर आईडी, मेटाडेटा, और ग्राहक होते हैं दावे. डिवाइस, एपीआई का मुख्य काम करते हैं. इसलिए, इनका इस्तेमाल करीब-करीब सभी ऐप्लिकेशन में किया जाता है तरीकों का इस्तेमाल करना होगा. ज़्यादा जानने के लिए, Device देखें.
DeviceIdentifier
किसी मैन्युफ़ैक्चरर की पहचान करने के लिए, IMEI या MEID जैसे हार्डवेयर आईडी इनकैप्सुलेट करता है डिवाइस. डिवाइस को टारगेट करने के लिए, DeviceIdentifier का इस्तेमाल करें जिसे आपको ढूँढना, अपडेट करना या उस पर दावा करना हो. इस बारे में ज़्यादा जानने के लिए, पढ़ें आइडेंटिफ़ायर.
DeviceMetadata
डिवाइस के लिए, मेटाडेटा के की-वैल्यू पेयर को सेव करता है. इस्तेमाल की जाने वाली चीज़ें आपके संगठन का मेटाडेटा सेव करने के लिए DeviceMetadata. यहां की यात्रा पर हूं ज़्यादा जानें, डिवाइस मेटाडेटा पढ़ें.

आपका ऐप्लिकेशन जिन एपीआई के तरीकों और संसाधनों का इस्तेमाल कर सकता है उन्हें सूची में जोड़ने के लिए, एपीआई का संदर्भ.

ग्राहक बनाएं

Android डिवाइसों के लिए, ग्राहक बनाने की ज़िम्मेदारी रीसेलर की होती है अपने ग्राहक की ओर से Google खाता मैनेज कर सकता है. ग्राहक इस खाते का इस्तेमाल इन कामों के लिए करेगा 'पहले से तैयार डिवाइस' सुविधा वाले पोर्टल को ऐक्सेस करें, ताकि उनके लिए प्रॉविज़निंग की सेटिंग कॉन्फ़िगर की जा सकें डिवाइस. यह उन ChromeOS डिवाइसों के लिए ज़रूरी नहीं है जिनके पास पहले से ही Google खाता है वह Workspace खाता चुनें जिसका इस्तेमाल करके, वह अपनी प्रॉविज़निंग की सेटिंग कॉन्फ़िगर कर सकेगा.

create एपीआई तरीके को कॉल करके इस तरह बनाया जा सकता है: 'पहले से तैयार डिवाइस' सुविधा के लिए ग्राहक खाते. क्योंकि आपके ग्राहक ज़ीरो-टच रजिस्ट्रेशन पोर्टल पर दी गई है, तो आपके ऐप्लिकेशन के उपयोगकर्ता को पुष्टि करें कि यह सही है. ग्राहक आईडी बनाने के बाद, ग्राहक के नाम में बदलाव नहीं किया जा सकता ग्राहक.

आपको कम से कम एक कॉर्पोरेट ईमेल पता शामिल करना होगा. Google खाता, मालिक बनने के लिए. निजी Gmail खातों का इस्तेमाल एपीआई. अगर ग्राहक को खाता जोड़ने में मदद चाहिए, तो निर्देश Google खाता जोड़ें.

एपीआई को कॉल करके ग्राहक बनाने के बाद, वह अपने कर्मचारियों पोर्टल ऐक्सेस — आप अपने ग्राहकों की प्रॉपर्टी में बदलाव नहीं कर सकते जो एपीआई का इस्तेमाल कर रहे हैं. स्निपेट नीचे बताया गया है कि आप ग्राहक कैसे बना सकते हैं:

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 डिवाइसों के लिए प्रमाणित किया गया डिवाइस आईडी.

नीचे दिया गया स्निपेट किसी डिवाइस पर दावा करने का तरीका बताता है:

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 किसी ग्राहक का डिवाइस मिला है.

विक्रेता

रीसेलर पार्टनर का इस्तेमाल करके, अपने डीलर नेटवर्क में वेंडर का इस्तेमाल किया जा सकता है वैश्विक पुनर्विक्रेता नेटवर्क के ऑपरेटर या बिक्री करने वाले किसी भी संगठन के अलग-अलग डिवाइस उपलब्ध हैं. वेंडर की मदद से अपने उपयोगकर्ताओं, ग्राहकों, और डिवाइस:

  • आपने जो वेंडर बनाया है वे 'पहले से तैयार डिवाइस' सुविधा वाले खाते या आपके हर खाते को नहीं देख सकते खाते में साइन इन करना होगा.
  • अपने वेंडर के ग्राहकों और डिवाइसों को देखा जा सकता है. साथ ही, उनका रजिस्ट्रेशन रद्द किया जा सकता है वेंडर के डिवाइसों पर काम करता है. हालांकि, अपने वेंडर को डिवाइस असाइन नहीं किए जा सकते ग्राहकों को ध्यान में रखकर बनाया गया है.

पोर्टल का इस्तेमाल करके अपने लिए वेंडर बनाएं संगठन — एपीआई का इस्तेमाल नहीं किया जा सकता. खाते में आपकी भूमिका नया वेंडर बनाने के लिए, मालिक. अगर आपके संगठन में वेंडर हैं, आप 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'])

अगर आपके पास कई तरह के डिवाइस हैं, तो आपको यह जानना होगा कि किस रीसेलर या वेंडर ने डिवाइस पर दावा किया. अंकों वाला रीसेलर आईडी पाने के लिए, डिवाइस के दावे के रिकॉर्ड में resellerId फ़ील्ड.

आपका संगठन, वेंडर के दावे वाले डिवाइस से दावा हटा सकता है. ऐसे अन्य एपीआई कॉल के लिए डिवाइस में बदलाव करें, तो आपको यह जांच करनी चाहिए कि आपके संगठन ने डिवाइस पर दावा किया है या नहीं देख लें. नीचे दिए गए उदाहरण में बताया गया है कि ऐसा कैसे किया जा सकता है:

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

लंबे समय तक चलने वाली बैच कार्रवाइयां

एपीआई में, डिवाइस के तरीकों के एसिंक्रोनस वर्शन शामिल हैं. ये तरीके कई डिवाइसों को एक साथ प्रोसेस करने की अनुमति देते हैं, जबकि सिंक्रोनस तरीके, हर एपीआई अनुरोध के लिए एक डिवाइस प्रोसेस करते हैं. एसिंक्रोनस तरीके के नाम एक साथ काम नहीं करने वाली प्रोसेस में सफ़िक्स होता है, उदाहरण के लिए claimAsync.

प्रोसेसिंग पूरी होने से पहले, एसिंक्रोनस एपीआई के तरीके नतीजे देते हैं. एसिंक्रोनस तरीके भी आपके ऐप्लिकेशन (या टूल) को आपके लंबे समय तक चलने वाली कार्रवाई के पूरा होने का इंतज़ार करते समय उपयोगकर्ताओं को. आपके ऐप्लिकेशन को चाहिए समय-समय पर कार्रवाई की स्थिति की जांच करें.

ऑपरेशंस

लंबे समय तक चलने वाले बैच ऑपरेशन को ट्रैक करने के लिए, 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 है, तो कार्रवाई अब भी जारी है दौड़ने.

जवाब

कार्रवाई पूरी होने के बाद, एपीआई कार्रवाई के नतीजे को अपडेट करता है. यहां तक कि अगर सभी या कोई भी अलग-अलग टास्क पूरा नहीं होता है. response फ़ील्ड DevicesLongRunningOperationResponse एक ऑब्जेक्ट है, जो ऑपरेशन के दौरान हर डिवाइस की प्रोसेसिंग का ब्यौरा देता है.

successCount फ़ील्ड की जांच करके, बेहतर तरीके से यह पता लगाएं कि कोई टास्क पूरा नहीं हुआ और नतीजों की बड़ी सूचियों में जाकर बार-बार न करें. इसका perDeviceStatus फ़ील्ड DevicesLongRunningOperationResponse यहां दी गई सूची में शामिल है OperationPerDevice इंस्टेंस में हर डिवाइस की जानकारी कार्रवाई. सूची का क्रम, मूल अनुरोध में मौजूद टास्क से मेल खाता है.

हर OperationPerDevice टास्क में result फ़ील्ड और रिमाइंडर की खास जानकारी शामिल होती है सर्वर को मिले अनुरोध का. देखें कि टास्क पूरा हुआ या नहीं result फ़ील्ड का इस्तेमाल करके.

नीचे दिया गया JSON स्निपेट किसी कार्रवाई से मिलने वाले सामान्य जवाब का हिस्सा दिखाता है 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 कार्रवाई में अपडेट की संख्या दिखाता है. यह आपके फ़ोन में मौजूद अपडेट की संख्या से अनुरोध करें कि एपीआई कुछ अपडेट को पार्स नहीं कर सकता.

नीचे दिए गए आसान उदाहरण में बताया गया है कि कोई ऐप्लिकेशन, प्रोग्रेस मेटाडेटा का इस्तेमाल इन कामों के लिए कैसे कर सकता है पोलिंग के इंटरवल सेट कर सकते हैं. आपको अपने ऐप्लिकेशन में, बेहतर तरीके से काम करने वाले किसी टास्क की ज़रूरत पड़ सकती है मतदान के लिए रनर. आपको गड़बड़ी की जानकारी देने वाली सुविधा भी जोड़नी होगी.

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 एपीआई का तरीका डिवाइस की बहुत बड़ी सूची दिखा सकता है. रिस्पॉन्स का साइज़ कम करने के लिए, यह और एपीआई के अन्य तरीके (जैसे कि partners.devices.findByIdentifier) सहायता पेज पर मौजूद नतीजे. पेज वाले नतीजों की मदद से, आपका ऐप्लिकेशन बार-बार बड़ी सूचियों को एक बार में एक पेज पर देखने और उन्हें प्रोसेस करने की सुविधा मिलती है.

एपीआई मेथड को कॉल करने के बाद, देखें कि जवाब में 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);

अगले चरण

अब आपको पता है कि एपीआई कैसे काम करता है. इसलिए, अब इन उदाहरणों को क्विकस्टार्ट के साथ आज़माएं Java, .NET या Python.