Power your Unity Project with AppGallery Connect API!

Samet Güzel
Huawei Developers
Published in
4 min readJan 4, 2022
Photo by @julientromeur on Unsplash

📖 Introduction 📖

In this article, I’ll be guiding you on how to implement Connect API into the Unity game engine with HMS Unity Plugin v2.1.x version.

🚧 Getting Started 🚧

First, we need to create a project on AGC which is explained here. After that, we need to install the appropriate Unity package depending on our Unity version. You can find released versions here. I’ll be using the current latest version which is v2.1.0 for my Unity 2020 version. As a final step before coding, we need to import HMS Unity Plugin into our project explained here.

✨ Setting up Connect API✨

We need to set up a credential for the Connect API. First, go to your AppGallery Connect and click on “Users and Permissions”. After that, you should see “Connect API” under “API key”. Click on that and it will open a page with Connect API keys. HMS Unity Plugin is only supporting API Client mode.

Connect API Key Page

Let’s create a key for API Client Mode! There is a button called “Create” in the top right corner. Please click on that to start creating the key.

Create button for API Client

It will prompt a pop-up for you to enter some information. Write a name for your key and select the project if you want. You can also assign specific roles for specific keys! After entering all information, click on “OK” to finish creating the key.

Connect API Key Information

After creating the key, you should see a new key in the key list.

API Client Key List

Congratulations! You’ve successfully finished creating a key for the Connect API!

⌨️ Configuring Connect API in Unity⌨️

To be able to use the Connect API in Unity, we need to generate a token for the API calls. For generating a token, we need “Client Id” and “Client Secret(Key)” parameters. We can get these parameters from the key we’ve created for the Connect API.

Client ID and Client Secret(Key)

Go to Unity and follow Huawei > Connect API > Token Obtainer to get a token for the Connect API. Please enter the credentials you’ve taken from AppGallery Connect and click on the “Obtain Token” button.

Token Obtainer Window

After clicking on Obtain Token button, if the operation is successful, you should see the token printed in the Unity console. HMS Unity Plugin will automatically save all the information you’ve entered along with the acquired token. So you don’t need to enter Client Id or Client secret again for that project.

Successfully created Token

Tokens have 48 hours of expiration time. But do not worry, HMS Unity Plugin will renew the token if it is expired.

💡 Conclusion 💡

We’ve learned how to create Connect API keys in AppGallery Connect, how to acquire tokens for the Connect API in Unity to be able to use Connect API features such as Publishing API and PMS API.

I hope this article has shown the configuration of Connect API that will power up your project!

Don’t hesitate to ask questions.

--

--