简体   繁体   中英

How to send push to Huawei device using Huawei Push Kit API?

I want to send push from server to Huawei device with Huawei Push Kit integrated. I have deviceToken from device, but when I try so send push message using API I receive error:

80300002: No permission to send message to these tmIDs

This error can be caused be wrong AppId , used in API url path.

AppId can be found in console so: App Gallery Connect -> My projects -> YOUR_PROJECT -> Project settings . On this screen AppId is Application ID , which can be found above SHA-256 of your signing keys.

在此处输入图像描述

So, working request using looks like (for notification push (shown in notification bar)):

curl --location --request POST 'https://push-api.cloud.huawei.com/v1/APP_ID_FROM_CONSOLE/messages:send' \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
    "validate_only": false,
    "message": {
        "notification": {
            "title": "Hello!",
            "body": "Hello, shirley!",
            "click_action": {
                "type": 3
            }
        },
        "android": {
            "urgency": "NORMAL",
            "ttl": "10000s",
            "notification": {
                "title": "Hello!",
                "body": "Hello, shirley!",
                "click_action": {
                    "type": 3
                }
            }
        },
        "token": [
            "DEVICE_TOKEN"
        ]
    }
}'

To get ACCESS_TOKEN see this question: How to get access token for Huawei Api for sending push to device?


You can find more information in documentation: https://developer.huawei.com/consumer/en/doc/development/HMSCore-References-V5/https-send-api-0000001050986197-V5#EN-US_TOPIC_0000001070412173__section134322259125

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