MobilityData / gtfs-realtime-bindings

Language bindings generated from the GTFS Realtime protocol buffer spec for popular languages.
Apache License 2.0
370 stars 127 forks source link

Protocol message end-group tag did not match expected tag. #134

Closed mingsheng13 closed 5 months ago

mingsheng13 commented 5 months ago

Hi, I'm trying to get the feed by calling the API below.

public static void main(String[] args) throws Exception
    {
        try
        {
            String urlString = "https://api.nationaltransport.ie/gtfsr/v2/gtfsr?format=json";
            URL url = new URL(urlString);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            //Request headers
            connection.setRequestProperty("Cache-Control", "no-cache");

            connection.setRequestProperty("x-api-key", YOUR_API_KEY);

            connection.setRequestMethod("GET");

            int status = connection.getResponseCode();
            System.out.println(status);
            FeedMessage feed = FeedMessage.parseFrom(connection.getInputStream());
            for (FeedEntity entity : feed.getEntityList()) {
                if (entity.hasTripUpdate()) {
                    System.out.println(entity.getTripUpdate());
                }
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }

This error is thrown: com.google.protobuf.InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag. If I tried to read this into a plain text, it works fine. Am I doing something wrong here? I suspect it might be that I'm requesting the wrong format? Sorry, I'm new to all these.

mingsheng13 commented 5 months ago

I figured it out by using the pb format.