如何使用华为Push Kit API向华为设备发送推送信息? [英] How to send push to Huawei device using Huawei Push Kit API?

查看:369
本文介绍了如何使用华为Push Kit API向华为设备发送推送信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从服务器向集成了Huawei Push Kit的华为设备发送推送.我有来自设备的 deviceToken ,但是当我尝试使用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:没有向这些tmID发送消息的权限

80300002: No permission to send message to these tmIDs

推荐答案

API URL路径中使用的 AppId 可能是错误的.

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

AppId ,因此: App Gallery Connect->我的项目->YOUR_PROJECT->项目设置.在此屏幕上, AppId Application ID ,可以在您的签名密钥的 SHA-256 上方找到.

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"
        ]
    }
}'

要获取 ACCESS_TOKEN ,请参阅以下问题:如何获取华为Api的访问令牌以将推送发送到设备?/a>

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

您可以在文档中找到更多信息:https://developer.huawei.com/consumer/zh-CN/doc/development/HMSCore-References-V5/https-send-api-0000001050986197-V5#EN-US_TOPIC_0000001070412173__section134322259125

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

这篇关于如何使用华为Push Kit API向华为设备发送推送信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆