我正在使用node-zendesk
包进行基于NodeJS的项目。该库提供提取文章列表的功能。但是该方法采用Object.prototype.list
的形式,我不知道如何访问此方法。
node-zendesk
软件包位于node_modules
中。
我需要访问的方法在node-zendesk/lib/client/helpcenter/articles.js
var util = require('util'),
Client = require('../client').Client
var Articles = exports.Articles = function(options) {
this.jsonAPINames = ['articles', 'article'];
this.sideLoadMap = [{
field: 'author_id',
name: 'user',
dataset: 'users'
},
{
field: 'section_id',
name: 'section',
dataset: 'sections'
},
{
field: 'category_id',
name: 'category',
dataset: 'categories'
}
];
Client.call(this, options);
};
util.inherits(Articles, Client);
Articles.prototype.list = function(cb) {
this.requestAll('GET', ['articles'], cb); //all
};
我需要访问Articles.prototype.list
。我尝试过的是:
var zendesk = require('node-zendesk');
var client = zendesk.createClient({
username: < my_username > ,
token: < my_token > ,
remoteUri: < my_remoteUri > ,
helpcenter: true
});
client.articles.list((err, req, result) => {
if (err) {
console.log(err);
return;
}
console.log(JSON.stringify(result)); //gets the first page
});
错误是这样的:
{ Error: Zendesk Error (404): Item not found
> at checkRequestResponse (/<project_path>/node_modules/node-zendesk/lib/client/client.js:259:13)
at requestCallback (/<project_path>/node_modules/node-zendesk/lib/client/client.js:274:3)
at Request._callback (/<project_path>/node_modules/node-zendesk/lib/client/client.js:111:5)
at Request.self.callback (/<project_path>/node_modules/request/request.js:185:22)
at Request.emit (events.js:189:13)
at Request.EventEmitter.emit (domain.js:441:20)
at Request.<anonymous> (/<project_path>/node_modules/request/request.js:1161:10)
at Request.emit (events.js:189:13)
at Request.EventEmitter.emit (domain.js:441:20)
at IncomingMessage.<anonymous> (/<project_path>/node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:277:13)
at IncomingMessage.emit (events.js:194:15)
at IncomingMessage.EventEmitter.emit (domain.js:441:20)
at endReadableNT (_stream_readable.js:1103:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
帮助我访问Articles.prototype.list
方法。
答案 0 :(得分:0)
似乎您正在正确访问articles
'列表方法。由于404 Item Not Found
,您可能只会收到网络错误。