条形码扫描器读取条形码并显示在控制台日志中,但如何在Google Book API上查找该书。标题,作者和发布年份等书籍详细信息应显示在不同的页面上。这是我遵循的插件:https://github.com/EddyVerbruggen/nativescript-barcodescanner
这是我的 hardcopy-view-model.js文件
var observable_1 = require("data/observable");
var dialogs_1 = require("ui/dialogs");
var view = require("ui/core/view");
var nativescript_barcodescanner = require("nativescript-barcodescanner");
const httpModule = require("http");
var BarCodeModel = (function (_super) {
__extends(BarCodeModel, _super);
function BarCodeModel() {
_super.call(this);
this.barcodeScanner = new nativescript_barcodescanner.BarcodeScanner();
}
BarCodeModel.prototype.doCheckHasCameraPermission = function () {
this.barcodeScanner.hasCameraPermission().then(function (permitted) {
dialogs_1.alert({
title: "Has Camera permission?",
message: permitted ? "YES" : "NO",
okButtonText: "OK"
});
}, function (err) {
dialogs_1.alert(err);
});
};
BarCodeModel.prototype.doScanWithTorch = function () {
this.scan(false, true, true, "landscape");
};
;
BarCodeModel.prototype.doScanLandscape = function () {
this.scan(false, true, true, "landscape");
};
;
BarCodeModel.prototype.scan = function () {
this.barcodeScanner.scan({
cancelLabel: "EXIT. Also, try the volume buttons!",
cancelLabelBackgroundColor: "#333333",
message: "Tap the bulb button or Use the volume button for turning on
light",
showFlipCameraButton: false,
preferFrontCamera: false,
showTorchButton: true,
beepOnScan: true,
torchOn: false,
closeCallback: function () { console.log("Scanner closed"); },
resultDisplayDuration: 500,
orientation: "landscape",
openSettingsIfPermissionWasPreviouslyDenied: true
}).then(
function(result) {
console.log("---- scanned " +result.text);
httpModule.request({
url: "https://www.googleapis.com/books/v1/volumes?
q=isbn:"+result,
method: "GET"
}).then((response) => {
var obj = response.content.toJSON();
console.log("Book: " +obj);
console.log(JSON.parse(response));
alert({
title:"Scan Result",
message: "Barcode Format: " + result.format + "\nCode: " +
result.text + "\nBook Title: " + result.response,
okButtonText:"OK"
});
});
},
function(error) {
console.log("No scan: " + error);
});
};
;
return BarCodeModel;
}(observable_1.Observable));
exports.BarCodeModel = BarCodeModel;
答案 0 :(得分:0)
我认为问题在于您需要在URL中传递result.text。 result.text具有实际的条形码。
url:“ https://www.googleapis.com/books/v1/volumes?q=isbn:” + result.text,