我正在尝试使用url并将其放置在下面的代码中,但是出现错误

时间:2019-12-27 08:51:03

标签: javascript node.js protocol-buffers google-drive-realtime-api gtfs

我正在尝试使用API​​获取当前的公交发车时间,并且使用了以下代码... API信息来自另一家公司。我正在评估protobuf文件中错误的可能性。你能帮忙吗?

  

错误:偏移量12处的电线类型7无效       在BufferReader.Reader.skipType(/home/runner/node_modules/gtfs-realtime-bindings/node_modules/protobufjs/src/reader.js:375:19)       在Function.decode(/home/runner/node_modules/gtfs-realtime-bindings/gtfs-realtime.js:148:28)       在Request._callback(/home/runner/index.js:12:66)       在Request.self.callback(/home/runner/node_modules/request/request.js:185:22)       在Request.emit(events.js:198:13)       在Request.EventEmitter.emit(domain.js:448:20)       应要求。 (/home/runner/node_modules/request/request.js:1161:10)       在Request.emit(events.js:198:13)       在Request.EventEmitter.emit(domain.js:448:20)       在IncomingMessage。 (/home/runner/node_modules/request/request.js:1083:12)

var GtfsRealtimeBindings = require('gtfs-realtime-bindings');
var request = require('request');
var protobuf = require("protobufjs");

var requestSettings = {
  method: 'GET',
  url: 'url',
  encoding: null
};
request(requestSettings, function (error, response, body) {
  if (!error && response.statusCode == 200) {
    var feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(body);
    feed.entity.forEach(function(entity) {
      if (entity.trip_update) {
        console.log(entity.trip_update);
      }
    });
  }
});

0 个答案:

没有答案