The HMS Core push service allows developers to access the Push server using the HTTPS protocol. Postman is an interface testing tool that simulates various HTTP requests initiated by users, sends the request data to the server, and obtains the corresponding response results. Postman can simulate requests from the developer server to apply for an Access Token and call interfaces such as authentication.
Therefore, many developers choose to use Postman to test the push interface when testing the effect of pushing on the client side or locating push problems. For example, when a developer wants to use the interface to push test messages but is inconvenient to use the application's official server to push directly, they can use Postman to simulate the server's push request. Or the server interface cannot be debugged, and you are not sure whether there is a problem with the parameters, you can use postman to verify whether the request is successful. This article will introduce the specific steps of using Postman to call the push interface of HMS Core.
1. Download and install Postman
Download address: https://www.postman.com/downloads/ , click Download, download the corresponding version, and then install it. This article uses version v7.36.1.
If the network uses a proxy, you need to configure a proxy for Postman (if the network does not have a proxy, please ignore it):
- Open the File menu, click the Settings menu, and the settings interface will pop up.
- Select Proxy in the settings interface to configure your network proxy.
2. Call the authentication interface to obtain the Access Token.
- Create a new Tab in Postman, enter the interface address, and select the POST method:
Post address: https://oauth-login.cloud.huawei.com/oauth2/v3/token
- Select body, check "x-www-form-urlencoded", and enter the parameter name and corresponding value in the list below.
The three parameters are described as follows:
grant_type - fixed value "client_credentials".
client_id - For AppGallery Connect-like apps, this value is the Client ID of the OAuth 2.0 client ID (credentials) in the app.
client_secret - For AppGallery Connect-like apps, this value is the Client Secret of the OAuth 2.0 client ID (credentials) in the app.
Click send, you can call the interface to return access_token, as shown in the following figure:
- Save the debugging configuration, press ctrl+s, enter the name "Get Token", and create a new directory "push" to save.
3. Call the message push interface to send the Push message
- Create a new Tab in Postman, enter the interface address (replace [appid] with the actual appid), and select the POST method:
Post address: https://push-api.cloud.huawei.com/v1/ [appId]/messages:send
- Select Authorization, select "Bearer Token" for TYPE, and then enter the access_token obtained in the second step in the Token input box, as shown in the following figure:
- Select Body, select "raw", select "JSON" from the drop-down box, then copy the message content in the input box below, click send, and you can send the message, as shown below:
- Save the debugging configuration, press ctrl+s, enter the name "Send Message", and save it in the directory "push".
Fourth, use Postman to generate commands for other common tools/languages
Using Postman's existing successful debugging interface, commands for other tools can be automatically generated, such as commonly used cURL, Nodejs, Python, Ruby, etc., which can be copied and used directly.
How to get it: On the right side of the window, click Code, the command page will pop up, and you can select the command in the language you want.
Finally, the example file exported using Postman is attached, and developers in need can directly import the test.
Learn more details>>
Visit the official website of Huawei Developer Alliance
Get development guidance documents
Huawei Mobile Services Open Source Warehouse Address: GitHub , Gitee
Follow us to know the latest technical information of HMS Core for the first time~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。