问题
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
- Add header
Content-Type: application/x-www-form-urlencoded
- 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