Guide de démarrage rapide .NET pour les revendeurs
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Suivez les étapes de ce guide de démarrage rapide. En 10 minutes environ, vous aurez une application de console .NET C# simple qui envoie des requêtes à l'API de revendeur d'enregistrement sans contact.
Prérequis
Pour exécuter ce guide de démarrage rapide, vous avez besoin des éléments suivants :
Un compte Google, membre de votre compte revendeur d'enregistrement sans contact. Si vous n'avez pas encore intégré le portail, suivez les étapes de la section Premiers pas du guide du portail pour les revendeurs.
Visual Studio 2013 ou version ultérieure
Accès à Internet et à un navigateur Web.
Étape 1 : Activez l'API d'inscription sans contact
Utilisez cet assistant pour créer ou sélectionner un projet dans la Google Developers Console et activer automatiquement l'API. Cliquez sur Continue (Continuer), puis sur Go to credentials (Accéder à Identifiants).
Définissez À quelles données accéderez-vous ? sur Données d'application.
Cliquez sur Suivant. Vous devriez être invité à créer un compte de service.
Attribuez un nom descriptif à Nom du compte de service.
Notez l'ID de compte de service (qui ressemble à une adresse e-mail), car vous en aurez besoin plus tard.
Définissez Rôle sur Comptes de service > Utilisateur du compte de service.
Cliquez sur OK pour terminer la création du compte de service.
Cliquez sur l'adresse e-mail du compte de service créé.
Cliquez sur **Clés**.
Cliquez sur "Ajouter une clé", puis sur "Créer une clé".
Pour "Type de clé", sélectionnez "JSON".
Cliquez sur Créer. La clé privée est alors téléchargée sur votre ordinateur.
Cliquez sur "Fermer".
Déplacez le fichier vers votre répertoire de travail et renommez-le service_account_key.json.
Étape 2 : Associer le compte de service
Ouvrez le portail d'enregistrement sans contact. Pour cela, vous devrez peut-être vous connecter.
Cliquez sur settings_ethernetComptes de service.
Cliquez sur addAssocier le compte de service.
Définissez le champ Adresse e-mail sur l'adresse du compte de service que vous avez créé.
Cliquez sur Associer le compte de service pour utiliser le compte de service avec votre compte d'enregistrement sans contact.
Étape 3 : Préparer le projet
Créez un projet Application console C# .NET Core dans Visual Studio.
Ouvrez le Gestionnaire de paquets, sélectionnez la source de paquets nuget.org, puis ajoutez les paquets suivants :
Faites glisser service_account_key.json (téléchargé à l'étape 1) dans l'explorateur de solutions Visual Studio.
Sélectionnez service_account_key.json, puis accédez à la fenêtre "Propriétés" et définissez le champ Copier dans le répertoire de sortie sur Toujours copier.
Remplacez le contenu de Program.cs par le code suivant.
Insérez votre propre ID de partenaire revendeur comme valeur pour PartnerId (première ligne de l'application).
usingGoogle.Apis.AndroidProvisioningPartner.v1;usingGoogle.Apis.AndroidProvisioningPartner.v1.Data;usingGoogle.Apis.Auth.OAuth2;usingGoogle.Apis.Services;usingSystem;usingSystem.Collections.Generic;usingSystem.IO;namespaceZeroTouchResellerQuickstart{classProgram{// TODO: replace this with your partner reseller ID.staticlongPartnerId=11036885;// Use a single scope for the all methods in the reseller API.staticreadonlystring[]Scopes={"https://www.googleapis.com/auth/androidworkprovisioning"};staticstringApplicationName="Zero-touch Reseller .NET Quickstart";staticvoidMain(string[]args){// Create a credential to authorize API requests using a service account key.// The service account must be linked using the zero-touch portal.ServiceAccountCredentialcredential;using(varstream=newFileStream("service_account_key.json",FileMode.Open,FileAccess.Read)){credential=GoogleCredential.FromStream(stream).CreateScoped(Scopes).UnderlyingCredentialasServiceAccountCredential;}// Create a zero-touch enrollment API service endpoint.varservice=newAndroidProvisioningPartnerService(newBaseClientService.Initializer{HttpClientInitializer=credential,ApplicationName=ApplicationName});// Send an API request to list all our customers.PartnersResource.CustomersResource.ListRequestrequest=service.Partners.Customers.List(PartnerId);ListCustomersResponseresponse=request.Execute();// Print out the details of each customer.IList<Company>customers=response.Customers;if(customers!=null){foreach(Companycustomerincustomers){Console.WriteLine("Name:{0} ID:{1}",customer.CompanyName,customer.CompanyId);}}else{Console.WriteLine("No customers found");}}}}
ID du partenaire
Les appels d'API nécessitent généralement votre ID de partenaire revendeur comme argument. Pour trouver votre ID de partenaire dans le portail d'inscription sans contact, procédez comme suit :
Ouvrez le portail. Pour cela, vous devrez peut-être vous connecter.
Cliquez sur settings_ethernetComptes de service.
Copiez votre numéro d'ID de partenaire sur la ligne Votre ID de revendeur.
Étape 5 : Exécuter l'exemple
Pour créer et exécuter l'exemple, cliquez sur play_arrow
Start (Démarrer) dans la barre d'outils de Visual Studio.
Dépannage
Expliquez-nous le problème dans le guide de démarrage rapide. Nous nous efforcerons de le résoudre. Pour découvrir comment l'enregistrement sans contact utilise les comptes de service pour autoriser les appels d'API, consultez la section Autorisation.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/29 (UTC).
[null,null,["Dernière mise à jour le 2025/08/29 (UTC)."],[[["\u003cp\u003eThis quickstart guide helps you set up a .NET C# console application to interact with the zero-touch enrollment reseller API in approximately 10 minutes.\u003c/p\u003e\n"],["\u003cp\u003eYou'll need a Google account associated with your zero-touch enrollment reseller account, Visual Studio 2013 or later, and internet access to get started.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves enabling the zero-touch enrollment API, creating and linking a service account, setting up a .NET project, and configuring the sample code with your reseller partner ID.\u003c/p\u003e\n"],["\u003cp\u003eA service account is created and linked in order to authorize API requests; service account keys must be carefully managed to maintain security.\u003c/p\u003e\n"],["\u003cp\u003eThe guide provides steps to build and run a sample application that lists your customers using the zero-touch enrollment reseller API.\u003c/p\u003e\n"]]],["This guide outlines creating a .NET C# console app to interact with the zero-touch enrollment reseller API. Key steps include: enabling the API via the Google Developers Console, creating and downloading a JSON service account key, and linking the service account in the zero-touch enrollment portal. Next, it requires creating a new .NET Core console application, adding necessary NuGet packages, and copying the service account key to the project. Finally, replace the code with the provided sample code including the partner ID, and then run the app.\n"],null,["# .NET quickstart for resellers\n\nFollow the steps in this quickstart guide, and in about 10 minutes you'll have\na simple .NET C# console app that makes requests to the zero-touch enrollment\nreseller API.\n\nPrerequisites\n-------------\n\nTo run this quickstart, you'll need:\n\n- A Google account, that's a member of your zero-touch enrollment reseller account. If you haven't onboarded yet, follow the steps in *Get started* in the [Reseller portal guide](/zero-touch/guides/portal).\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: Link the service account\n--------------------------------\n\n1. Open the zero-touch enrollment [portal](https://enterprise.google.com/android/zero-touch/resellers). You might need to sign in.\n2. Click settings_ethernet **Service\n accounts**.\n3. Click add **Link service account**.\n4. Set **Email address** to the address of the service account you created.\n5. Click **Link service account** to use the service account with your zero-touch enrollment account.\n\nStep 3: 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 4: Set up the sample\n-------------------------\n\n1. Drag `service_account_key.json` (downloaded in Step 1) 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.\n4. Insert your own [reseller partner ID](#partner-id) as the value for `PartnerId` (the app's first line).\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;\n\nnamespace ZeroTouchResellerQuickstart\n{\n class Program\n {\n // TODO: replace this with your partner reseller ID.\n static long PartnerId = 11036885;\n\n // Use a single scope for the all methods in the reseller API.\n static readonly string[] Scopes =\n { \"https://www.googleapis.com/auth/androidworkprovisioning\" };\n static string ApplicationName = \"Zero-touch Reseller .NET Quickstart\";\n\n static void Main(string[] args)\n {\n // Create a credential to authorize API requests using a service account key.\n // The service account must be linked using the zero-touch portal.\n ServiceAccountCredential credential;\n using (var stream =\n new FileStream(\"service_account_key.json\", FileMode.Open, FileAccess.Read))\n {\n credential = GoogleCredential.FromStream(stream)\n .CreateScoped(Scopes)\n .UnderlyingCredential as ServiceAccountCredential;\n }\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 // Send an API request to list all our customers.\n PartnersResource.CustomersResource.ListRequest request =\n service.Partners.Customers.List(PartnerId);\n ListCustomersResponse response = request.Execute();\n\n // Print out the details of each customer.\n IList\u003cCompany\u003e customers = response.Customers;\n if (customers != null)\n {\n foreach (Company customer in customers)\n {\n Console.WriteLine(\"Name:{0} ID:{1}\",\n customer.CompanyName,\n customer.CompanyId);\n }\n }\n else\n {\n Console.WriteLine(\"No customers found\");\n }\n }\n }\n}\n```\n\n### Partner ID\n\nAPI calls typically need your reseller partner ID as an argument. To find your\npartner ID from the zero-touch enrollment portal, follow the steps below:\n\n1. Open the [portal](https://enterprise.google.com/android/zero-touch/resellers). You might need to sign in.\n2. Click settings_ethernet **Service\n accounts**.\n3. Copy your partner ID number from the **Your reseller ID** line.\n\nStep 5: Run the sample\n----------------------\n\nTo build and run the sample, click play_arrow **Start** in the Visual Studio toolbar.\n\nTroubleshooting\n---------------\n\n\n[Tell us what went wrong]() with the quickstart and we'll work to\nfix it. To learn how zero-touch uses service accounts to authorize API calls, read\n[Authorization](/zero-touch/guides/auth).\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)\n- [Using OAuth 2.0 for Server to Server\n Applications](/identity/protocols/OAuth2ServiceAccount)"]]