【问题标题】:How do you send a notification from server using UrbanAirship?如何使用 UrbanAirship 从服务器发送通知?
【发布时间】:2013-01-11 08:17:38
【问题描述】:

我正在尝试从服务器发送通知,docs 说要 POST 到 /api/push/broadcast/,这是我通过以下代码完成的

$.ajax({
    type: 'POST',
    dataType: 'json',
    url: 'https://go.urbanairship.com/api/push/?callback=?',
    data: '{"android": {"alert": "hi"}}',
    contentType: "application/json",
    username:"P4...UBg",
    password:"fg...gDA",
    error: function(jqXHR, textStatus, errorThrown){
            // log the error to the console
            alert(
                "The following error occured: "+
                textStatus, errorThrown
            );
        },
});

我收到 500(内部服务器错误)。我添加了回调以防止“同源策略”错误,如建议的here。有谁知道正确的做法吗?

谢谢

【问题讨论】:

    标签: push-notification urbanairship.com


    【解决方案1】:

    我最初尝试以这种方式对他们的服务器进行设置(制作原始 $POST)。最后,我很高兴地发现他们有适用于大多数常用语言的模块。我们的服务器都是用 Python 编写的,所以我们使用了 Python 模块。以下是他们拥有的软件包列表:

    https://support.urbanairship.com/customer/portal/articles/60713-push-server-libraries

    我们所要做的就是将 .py 文件上传到我们的 bin 中,我们就可以像这样发送推送:

    airship_android = urbanairship.Airship(SECRET_KEY, MASTER_KEY)
    push_data = {"android": {"alert": notification_message, "extra": str(extra_data_str)}, "apids": [apid]}
    airship_android.push(push_data)
    

    希望对您有所帮助!

    【讨论】:

    • 我使用 Windows Azure 作为我的服务器,不幸的是我需要通过 JavaScript 发送它
    猜你喜欢
    • 2011-09-18
    • 1970-01-01
    • 2016-09-27
    • 2014-07-11
    • 1970-01-01
    • 2017-09-07
    • 1970-01-01
    • 1970-01-01
    • 2017-05-26
    相关资源
    最近更新 更多