简体   繁体   中英

How to get access token for Huawei Api for sending push to device?

I need to send push to Huawei device, which have app with Huawei Push Kit integrated. To do this I need accessToken. How to receive it? I've already create developer account and create project for app.

  1. You need to do POST request to https://oauth-login.cloud.huawei.com/oauth2/v3/token
  2. Add header Content-Type: application/x-www-form-urlencoded
  3. Add params:
    • grant_type=client_credentials
    • client_id=CLIENT_ID_FROM_DEV_CONSOLE
    • client_secret=CLIENT_SECRET_FROM_DEV_CONSOLE

Request using curl:

curl --location --request POST 'https://oauth-login.cloud.huawei.com/oauth2/v3/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=CLIENT_ID_FROM_DEV_CONSOLE' \
--data-urlencode 'client_secret=CLIENT_SECRET_FROM_DEV_CONSOLE'

CLIENT_ID_FROM_DEV_CONSOLE and CLIENT_SECRET_FROM_DEV_CONSOLE can be found in console so: App Gallery Connect -> My projects -> YOUR_PROJECT -> Project settings . On this screen CLIENT_ID_FROM_DEV_CONSOLE is Application ID and CLIENT_SECRET_FROM_DEV_CONSOLE is App secret , which can be found near SHA-256 of you signing keys.

在此处输入图像描述


To send push using accessToken see this question: How to send push to Huawei device using Huawei Push Kit API?


You can find more information in documentation: https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/open-platform-oauth-0000001053629189-V5#EN-US_TOPIC_0000001063738301__section12493191334711

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM