gpt4 book ai didi

javascript - 跑道 JS : Cannot successfully subscribe to push service

转载 作者:行者123 更新时间:2023-11-28 05:26:02 26 4
gpt4 key购买 nike

我想做什么

我想订阅推送通知,当我对跑道中的项目进行更改时通知我。

我为实现这一目标做了什么

我正在使用 Podio JS 库并已阅读 documentation并经历了the detailed example 。我按照说明:

  • 已成功通过 PODIO api 进行身份验证;和
  • 成功进行 podio.request 调用(通过 push 属性接收 responseBody)

我的代码的下一步如下:

var subscribe = getItem.then (function (responseBody){ 
return podio.push(responseBody.push).subscribe(callback);
});

var notification = subscribe.then (function () { // never gets here!
console.log ('subscribed');
});

什么不起作用

代码永远不会到达notification部分,因此不会执行console.log('subscribed')。即使我对 Podio 帐户中的相关项目进行了更改,我传递给 podio.push(responseBody.push).subscribe(callback) 的回调也永远不会被调用。

当我以 1000 毫秒的间隔运行 console.log(subscribe) 时,输出保持不变:

lib$es6$promise$promise$$Promise {
_id: 2,
_state: undefined,
_result: undefined,
_subscribers:
[ lib$es6$promise$promise$$Promise {
_id: 3,
_state: undefined,
_result: undefined,
_subscribers: [] },
[Function],
undefined ],
_onerror: null }

我的问题是什么

我非常感谢您帮助确定推送服务无法正常工作的原因,尽管我(据我所知)完全按照文档的指示进行了操作。

提前谢谢您!

最佳答案

推送服务的订阅实际上在 podio-js 中被破坏,并已在 1.6.0 版本中修复。 (如果对代码更改感兴趣,请参阅 this PR)

请升级到最新版本的 podio-js,然后就可以开始了。

一个小例子(使用 ES6 表示法)

// assuming you already have an authenticated SDK in the variable podio

const onNotificationReceived = (message) => {
console.log(message);
};

const subscribeToPushNotifications = (itemId) => {

podio.request('GET', `/item/${itemId}`).then((data) => {
podio.push(data.push).subscribe(this.onNotificationReceived)
.then(() => console.log(`All is well, we've been subscribed!`));
}).catch(err => {
throw new Error(err)
});

};

// Whatever item you want to receive notifications about
const itemId = 99999999;

subscribeToPushNotifications(itemId);

关于javascript - 跑道 JS : Cannot successfully subscribe to push service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40163159/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com