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

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-11 14:20:29

问题


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:


  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



来源:https://stackoverflow.com/questions/65359394/how-to-get-access-token-for-huawei-api-for-sending-push-to-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!