Node.js nodejs上本地比特币api分页的问题
我正在使用nodejs开发本地比特币API。这是密码Node.js nodejs上本地比特币api分页的问题,node.js,api,pagination,Node.js,Api,Pagination,我正在使用nodejs开发本地比特币API。这是密码 const adsList = async (action, options = {}, page) => { let prefix = action + '-' let countryCode = (options.countryCode) ? options.countryCode : false let countryName = (options.countryName) ? options.count
const adsList = async (action, options = {}, page) => {
let prefix = action + '-'
let countryCode = (options.countryCode) ? options.countryCode : false
let countryName = (options.countryName) ? options.countryName : false
let paymentMethod = (options.paymentMethod) ? options.paymentMethod : false
let currency = (options.currency) ? options.currency : false
let basePath = prefix + 'bitcoins-online'
let suffix = (page > 1) ? `.json?page=2` : '.json'
let path
if (currency) {
path = (paymentMethod) ? `${basePath}/${currency}/${paymentMethod}/${suffix}` : `${basePath}/${currency}/${suffix}`
} else if (countryCode && countryName) {
path = (paymentMethod) ? `${basePath}/${countryCode}/${countryName}/${paymentMethod}/${suffix}` : `${basePath}/${countryCode}/${countryName}/${suffix}`
} else if (!currency && !countryCode && !countryName) {
path = (paymentMethod) ? `${basePath}/${paymentMethod}/${suffix}` : `${basePath}/${suffix}`
}
let response = await get(path, true)
return response
}
现在,当我在没有页面的情况下打电话时,一切正常
adsList('sell', {
countryCode: 'co',
countryName: 'colombia'
}).then(response => {
console.log(response)
})
输出:
{
pagination: {
next: 'https://localbitcoins.com/sell-bitcoins-online/co/colombia/.json?page=2'
},
data: {
ad_list: [
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object]
],
ad_count: 50
}
}
{
error: {
message: 'HMAC authentication key and signature was given, but they are invalid.',
error_code: 41
}
}
啊,但是当我添加页面时:
adsList('sell', {
countryCode: 'co',
countryName: 'colombia'
}, 2).then(response => {
console.log(response)
})
这是输出:
{
pagination: {
next: 'https://localbitcoins.com/sell-bitcoins-online/co/colombia/.json?page=2'
},
data: {
ad_list: [
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
[Object], [Object]
],
ad_count: 50
}
}
{
error: {
message: 'HMAC authentication key and signature was given, but they are invalid.',
error_code: 41
}
}
我已经为此工作了几个小时,但搜索信息,但什么都没有,因此如果您有任何解决方案,我将不胜感激。您可以确认两件事。首先,
console.log
page
并确保正确传递。其次,在进行API调用之前,console.log
您的path
并比较两者。并尝试直接(通过浏览器或邮递员)给它打电话,确保它返回预期的响应。当I console.log页面按预期返回2时,路径等于response.pagination.next.ok中的路径好。你有没有试着直接通过浏览器打电话?把这个路径放在你的浏览器地址栏里,然后看看答案。顺便说一句,我从终端打开了链接,这是我制作控制台时得到的链接。首先,console.log
page
并确保正确传递。其次,在进行API调用之前,console.log
您的path
并比较两者。并尝试直接(通过浏览器或邮递员)给它打电话,确保它返回预期的响应。当I console.log页面按预期返回2时,路径等于response.pagination.next.ok中的路径好。你有没有试着直接通过浏览器打电话?把这个路径放在你的浏览器地址栏里,然后看看答案。顺便说一句,我从终端打开了链接,这是我创建console.log时得到的链接