NET.start للبدء السريع للعملاء
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
اتّبِع الخطوات الواردة في دليل البدء السريع هذا، وستحصل في غضون 10 دقائق تقريبًا على
تطبيق وحدة تحكّم بسيط بتنسيق .NET C# يُرسل طلبات إلى واجهة برمجة التطبيقات لميزة "التسجيل بدون تلامس"
للعملاء باستخدام حساب خدمة.
المتطلبات الأساسية
لتنفيذ هذه الخطوات السريعة، تحتاج إلى ما يلي:
- حساب خدمة مرتبط بحساب العميل في برنامج "إعداد الأجهزة الجوّالة للمؤسسات دفعةً واحدة"
راجِع الحصول على
البدء.
- Visual Studio 2013 أو إصدار أحدث
- الوصول إلى الإنترنت ومتصفّح الويب
الخطوة 1: تفعيل واجهة برمجة التطبيقات لميزة "إعداد الأجهزة الجوّالة للمؤسسات دفعةً واحدة"
- استخدِم هذا
معالج لإنشاء مشروع أو اختياره في Google Developers Console
وتفعيل واجهة برمجة التطبيقات تلقائيًا. انقر على متابعة، ثم الانتقال إلى بيانات الاعتماد.
.
- اضبط ما هي البيانات التي ستتمكّن من الوصول إليها؟ على بيانات التطبيق.
- انقر على التالي. سيُطلب منك إنشاء حساب
خدمة.
- أدخِل اسمًا وصفيًا لـ اسم حساب الخدمة.
- دوِّن رقم تعريف حساب الخدمة (الذي يبدو مثل عنوان بريد إلكتروني) لأنك ستحتاج إلى
لاستخدامه لاحقًا.
- اضبط الدور على حسابات الخدمة > مستخدم حساب الخدمة.
- انقر على تم لإنهاء إنشاء حساب الخدمة.
- انقر على عنوان البريد الإلكتروني لحساب الخدمة الذي أنشأته.
- انقر على **المفاتيح**.
- انقر على **إضافة مفتاح**، ثم انقر على **إنشاء مفتاح جديد**.
- بالنسبة إلى **نوع المفتاح**، اختَر **JSON**.
- انقر على إنشاء وسيتم تنزيل المفتاح الخاص على جهاز الكمبيوتر.
- انقر على **إغلاق**.
- انقل الملف إلى دليل العمل وأعِد تسميته
service_account_key.json
.
الخطوة 2: إعداد المشروع
- أنشئ مشروعًا جديدًا من نوع تطبيق وحدة تحكّم باستخدام لغة C# وإطار عمل .NET Core في Visual Studio.
- افتح "مدير الحِزم"، واختَر مصدر الحِزم nuget.org، وأضِف
الحِزم التالية:
Google.Apis.AndroidProvisioningPartner.v1
Google.Apis.Auth
لمزيد من المعلومات، يُرجى الاطّلاع على مستند Microsoft تثبيت ملف برمجي
واستخدامه.
الخطوة 3: إعداد العيّنة
- اسحب ملف
service_account_key.json
الذي تم تنزيله عند إنشاء
الجديدة إلى أداة Visual Studio Solution Explorer.
- اختَر "
service_account_key.json
"، ثم انتقِل إلى نافذة "الخصائص"
اضبط الحقل نسخ إلى دليل الإخراج على النسخ دائمًا.
- استبدِل محتويات
Program.cs
بالرمز التالي:
using Google.Apis.AndroidProvisioningPartner.v1;
using Google.Apis.AndroidProvisioningPartner.v1.Data;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
namespace ZeroTouchCustomerQuickstart
{
class Program
{
// A single scope is used for the zero-touch enrollment customer API.
static readonly string[] Scopes =
{ "https://www.googleapis.com/auth/androidworkzerotouchemm" };
static string ApplicationName = "Zero-touch Enrollment .NET Quickstart";
static void Main(string[] args)
{
GoogleCredential credential;
// Authenticate using the service account key
credential = GoogleCredential.FromFile("service_account_key.json")
.CreateScoped(Scopes);
// Create a zero-touch enrollment API service endpoint.
var service = new AndroidProvisioningPartnerService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName
});
// Get the customer's account. Because a customer might have more
// than one, limit the results to the first account found.
CustomersResource.ListRequest accountRequest = service.Customers.List();
accountRequest.PageSize = 1;
CustomerListCustomersResponse accountResponse = accountRequest.Execute();
if (accountResponse.Customers.Count == 0)
{
// No accounts found for the user. Confirm the Google Account
// that authorizes the request can access the zero-touch portal.
Console.WriteLine("No zero-touch enrollment account found.");
Environment.Exit(-1);
}
Company customer = accountResponse.Customers[0];
var customerAccount = String.Format("customers/{0}", customer.CompanyId);
// Send an API request to list all the DPCs available.
CustomersResource.DpcsResource.ListRequest request = service.Customers.Dpcs.
List(customerAccount);
CustomerListDpcsResponse response = request.Execute();
// Print out the details of each DPC.
IList<Dpc> dpcs = response.Dpcs;
foreach (Dpc dpcApp in dpcs)
{
Console.WriteLine("Name:{0} APK:{1}",
dpcApp.DpcName,
dpcApp.PackageName);
}
}
}
}
الخطوة 4: تشغيل العيّنة
لإنشاء النموذج وتشغيله، انقر على رمز play_arrow
البدء في شريط أدوات Visual Studio.
ملاحظات
- تجنب مشاركة ملف
service_account_key.json
مع أي شخص. تنبيه
وعدم تضمينه في مستودعات رمز المصدر يمكنك قراءة المزيد من النصائح على
التعامل مع أسرار حساب الخدمة.
مزيد من المعلومات
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThis quickstart guide helps you create a simple .NET C# console application that interacts with the zero-touch enrollment customer API using a service account in about 10 minutes.\u003c/p\u003e\n"],["\u003cp\u003eYou will need a service account linked to your zero-touch enrollment customer account, Visual Studio 2013 or later, and internet access to complete this process.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves creating or selecting a project in the Google Developers Console to enable the zero-touch enrollment API and creating a JSON service account key.\u003c/p\u003e\n"],["\u003cp\u003eThe project setup requires creating a .NET Core C# Console Application in Visual Studio and adding the \u003ccode\u003eGoogle.Apis.AndroidProvisioningPartner.v1\u003c/code\u003e and \u003ccode\u003eGoogle.Apis.Auth\u003c/code\u003e NuGet packages.\u003c/p\u003e\n"],["\u003cp\u003eThe sample code provided in this guide demonstrates how to use the service account key to authenticate, access the customer's account, and list the available DPCs (Device Policy Controllers) through the zero-touch enrollment API.\u003c/p\u003e\n"]]],["This guide outlines creating a .NET C# console app to interact with the zero-touch enrollment customer API. It involves creating a service account, enabling the API, and downloading a JSON key. The process includes setting up a new C# console project in Visual Studio, adding necessary NuGet packages, and placing the service account key in the project directory. The `Program.cs` file is updated with code to authenticate and then send an API request to list all DPCs and print them out in the console. Finally, run the application.\n"],null,["# .NET quickstart for customers\n\nFollow the steps in this quickstart guide, and in about 10 minutes you have\na simple .NET C# console app that makes requests to the zero-touch enrollment\ncustomer API using a service account.\n\nPrerequisites\n-------------\n\nTo run this quickstart, you need:\n\n- A service account, that's linked to you zero-touch enrollment customer account. See [Get\n started](/zero-touch/guides/customer/service-accounts).\n- Visual Studio 2013 or later.\n- Access to the internet and a web browser.\n\nStep 1: Turn on the zero-touch enrollment API\n---------------------------------------------\n\n1. Use [this\n wizard](https://console.developers.google.com/start/api?id=androiddeviceprovisioning.googleapis.com) to create or select a project in the Google Developers Console and automatically turn on the API. Click **Continue** , then **Go to credentials**.\n2. Set **What data will you be accessing?** to *Application data*.\n3. Click **Next**. You should be prompted to create a service account.\n4. Give a descriptive name for **Service account name**.\n5. Note the **Service account ID** (it looks like an email address) because you'll use it later.\n6. Set **Role** to *Service Accounts \\\u003e Service Account User*.\n7. Click **Done** to finish creating the service account.\n8. Click the email address for the service account that you created.\n9. Click \\*\\*Keys\\*\\*.\n10. Click \\*\\*Add key\\*\\*, then click \\*\\*Create new key\\*\\*.\n11. For \\*\\*Key type\\*\\*, select \\*\\*JSON\\*\\*.\n12. Click **Create** and the private key downloads to your computer.\n13. Click \\*\\*Close\\*\\*.\n14. Move the file to your working directory and rename it `service_account_key.json`.\n\n| **Warning:** Service account keys can become a security risk if not managed carefully. For advice see [best practices for managing API keys](https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys).\n\nStep 2: Prepare the project\n---------------------------\n\n1. Create a new .NET Core C# *Console Application* project in Visual Studio.\n2. Open the Package Manager, select the package source **nuget.org** , and add the following packages:\n - `Google.Apis.AndroidProvisioningPartner.v1`\n - `Google.Apis.Auth`\n\nTo learn more, read the Microsoft document [Install and use a\npackage](https://docs.microsoft.com/en-us/nuget/quickstart/use-a-package).\n\nStep 3: Set up the sample\n-------------------------\n\n1. Drag the `service_account_key.json` you downloaded when you created your service account into your Visual Studio Solution Explorer.\n2. Select `service_account_key.json`, and then go to the Properties window and set **Copy to output directory** field to *Always copy*.\n3. Replace the contents of `Program.cs` with the following code:\n\n```c#\nusing Google.Apis.AndroidProvisioningPartner.v1;\nusing Google.Apis.AndroidProvisioningPartner.v1.Data;\nusing Google.Apis.Auth.OAuth2;\nusing Google.Apis.Services;\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Threading;\n\nnamespace ZeroTouchCustomerQuickstart\n{\n class Program\n {\n // A single scope is used for the zero-touch enrollment customer API.\n static readonly string[] Scopes =\n { \"https://www.googleapis.com/auth/androidworkzerotouchemm\" };\n static string ApplicationName = \"Zero-touch Enrollment .NET Quickstart\";\n\n static void Main(string[] args)\n {\n GoogleCredential credential;\n\n // Authenticate using the service account key\n credential = GoogleCredential.FromFile(\"service_account_key.json\")\n .CreateScoped(Scopes);\n\n // Create a zero-touch enrollment API service endpoint.\n var service = new AndroidProvisioningPartnerService(new BaseClientService.Initializer\n {\n HttpClientInitializer = credential,\n ApplicationName = ApplicationName\n });\n\n // Get the customer's account. Because a customer might have more\n // than one, limit the results to the first account found.\n CustomersResource.ListRequest accountRequest = service.Customers.List();\n accountRequest.PageSize = 1;\n CustomerListCustomersResponse accountResponse = accountRequest.Execute();\n if (accountResponse.Customers.Count == 0)\n {\n // No accounts found for the user. Confirm the Google Account\n // that authorizes the request can access the zero-touch portal.\n Console.WriteLine(\"No zero-touch enrollment account found.\");\n Environment.Exit(-1);\n }\n Company customer = accountResponse.Customers[0];\n var customerAccount = String.Format(\"customers/{0}\", customer.CompanyId);\n\n\n // Send an API request to list all the DPCs available.\n CustomersResource.DpcsResource.ListRequest request = service.Customers.Dpcs.\n List(customerAccount);\n CustomerListDpcsResponse response = request.Execute();\n\n // Print out the details of each DPC.\n IList\u003cDpc\u003e dpcs = response.Dpcs;\n foreach (Dpc dpcApp in dpcs)\n {\n Console.WriteLine(\"Name:{0} APK:{1}\",\n dpcApp.DpcName,\n dpcApp.PackageName);\n }\n\n }\n }\n}\n```\n\nStep 4: Run the sample\n----------------------\n\nTo build and run the sample, click play_arrow **Start** in the Visual Studio toolbar.\n\nNotes\n-----\n\n- Avoid sharing your `service_account_key.json` file with anyone. Be careful not to include it in source code repositories. You can read more advice on [handling service account secrets](https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys).\n\nLearn more\n----------\n\n- [Google Developers Console help documentation](/console/help/new)\n- [Google API Client Library for .NET\n documentation](/api-client-library/dotnet)"]]