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

别等时光非礼了梦想. 提交于 2021-02-05 09:00:21

问题


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


回答1:


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 curl 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



来源:https://stackoverflow.com/questions/65359941/how-to-send-push-to-huawei-device-using-huawei-push-kit-api

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