首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pushpad无法从node.js应用程序发送通知

Pushpad无法从node.js应用程序发送通知
EN

Stack Overflow用户
提问于 2018-05-15 10:01:53
回答 1查看 73关注 0票数 0

我编写了下面所示的代码来发送推送通知:

代码语言:javascript
复制
const pushpad = require('pushpad');
require('dotenv').config();
const axios = require('axios');


const project = new pushpad.Pushpad({
    authToken: process.env.PUSH_PAD_AUTH_TOKEN,
    projectId: process.env.PUSH_PAD_PROJECT_ID
});


console.log('called pushpad');



let notification = new pushpad.Notification({
    project: project,
    body: 'Hello world!',
    title: 'Website Name',
    targetUrl: 'http://example.com',
    iconUrl: 'http://example.com/assets/icon.png',
    imageUrl: 'http://example.com/assets/image.png',
    ttl: 604800,
    requireInteraction: true,
    customData: '123',
    actions: [
        {
            title: 'My Button 1',
            targetUrl: 'http://example.com/button-link',
            icon: 'http://example.com/assets/button-icon.png',
            action: 'myActionName'
        }
    ],
    starred: true,
    sendAt: new Date(Date.UTC(2016, 7 - 1, 25, 10, 9)),
    customMetrics: ['examples', 'another_metric']
});


// deliver to everyone
notification.broadcast(function (err, result) {
    console.log("error is " + err);
});


module.exports = notification;

但是,当我运行这段代码时,它就给了我错误的Unprocessable Entity。那么如何解决这个错误呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-15 11:21:27

可能你输入了一些错误的参数。例如,在使用customMetrics之前,必须在项目设置中定义它们。

使用简单的通知尝试相同的代码:

代码语言:javascript
复制
let notification = new pushpad.Notification({
  project: project,
  body: 'Hello world!'
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50347400

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档