2016-10-20 36 views
1

我想要做什麼波迪奧JS:不能成功訂閱推送服務

我想訂閱推送通知,通知我,當我修改的波迪奧項目。

我做了什麼來實現我使用波迪奧JS庫,並閱讀documentation,並通過the detailed example了這個

。我已按照說明:

  • 已成功通過PODIO api驗證;和
  • 成功做出了podio.request呼叫(接收responseBodypush屬性)

在我的代碼中的下一個步驟如下:

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.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 } 

我的問題是什麼

我將非常感謝幫助確定爲什麼Push服務不即使我 - 正如我所看到的 - 完全按照文檔的指示完成工作。

預先感謝您!

+0

作爲實驗,你可以嘗試和測試,如果改變是否是由其他人完成它的工作。我指的是這部分,即使我對我的跑道帳戶中的相關項目進行了更改。你可以讓其他人做出這些改變(或從不同的賬戶做)嗎? –

+0

@Pavlo:我現在已經試過了,它不會改變任何東西。結果是一樣的。我想知道我是否應該將[Faye](https://faye.jcoglan.com)連接到服務器。但關於Podio JS的指示在這方面沒有提及任何事情....? – rabbitco

回答

0

對推送服務的訂閱實際上在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); 
+0

是否可以訂閱APP,以便從APP上的每個項目獲取通知而不是訂閱每個項目? – EnigmaSAC

+1

您不能訂閱的應用程序,但你可以訂閱[/user/status](https://developers.podio。com/doc/users/get-user-status-22480),一旦你關注應用程序,它會給你所有關於創建/更新項目的通知。然後,您必須篩選出與您感興趣的應用程序無關的應用程序(例如其他應用程序,通知,聊天消息...) – domokun