Error in unserialize_pb
newboots861 opened this issue · 3 comments
Hi I am a bit of an amateur so please explain in detail. How do I resolve this error I am getting when I try to parse the protobuf response I get.
token <- 'apikey iT9QxFPpO4g5pKsmMjLYUogP95nyObkBMOxn'
req <- httr::POST(url = 'https://api.transport.nsw.gov.au/v1/gtfs/realtime/sydneytrains',
-
httr::add_headers(
-
"Content-Type" = "application/protobuf",Authorization=token))
output <- unserialize_pb(req$content)
[libprotobuf ERROR google/protobuf/message_lite.cc:123] Can't parse message of type "rexp.REXP" because it is missing required fields: rclass
Error in cpp_unserialize_pb(msg) : Failed to parse protobuf message
I want to save the response into a dataframe similar to what has been done with the json response here.
https://stackoverflow.com/questions/46069322/r-api-call-for-json-data-and-converting-to-dataframe
We no longer support networked protocol buffer work. That was always a step child because Google did not release their code for many years.
But now they did. So you should probably look into https://grpc.io/ -- it uses ProtocolBuffers under the hood but takes care of all handshaking and networking for you.
You mean that unserialize_pb can only be used for messages we have constructed ourselves?
Can https://grpc.io/ convert the message into something like a data frame or table? How would I go about doing that.
Yes. https://grpc.io can do all that, and there are copious demos and extensive documentation.
But you are asking in the wrong repo. This is about Protocol Buffers. What you are getting from the Sydney API is JSON as the StackOverflow post also shows. Look at packages such as jsonline
.
Good luck.