我只是尝试在我的ionic2应用程序中订阅salesforce中的主题,它甚至允许rest api调用但在订阅主题时出错:
Error during WebSocket handshake: Unexpected response code: 405
这是完整的代码:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import * as jsforce from "jsforce";
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController) {
var conn = new jsforce.Connection({
loginUrl : 'https://login.salesforce.com'
});
var username = 'XXXXXXXXXXXXXXX';
var password = 'XXXXXXXXXXXXXXX';
conn.login(username, password, function(err, userInfo) {
if (err) { return console.error(err); }
console.log(conn.accessToken);
console.log(conn.instanceUrl);
//this part of code works
conn.query("SELECT Id, Name FROM Account", function(err, result) {
if (err) { return console.error(err); }
console.log("total : " + result.totalSize);
console.log("fetched : " + result.records.length);
});
// this part of codes doesn't work
conn.streaming.topic("InvoiceStatementUpdates").subscribe(function(message) {
console.log('Event Type : ' + message.event.type);
console.log('Event Created : ' + message.event.createdDate);
console.log('Object Id : ' + message.sobject.Id);
});
// logged in user property
console.log("User ID: " + userInfo.id);
console.log("Org ID: " + userInfo.organizationId);
});
}
}