Android上的QPX API调用

时间:2017-04-27 18:54:45

标签: java android api request google-qpx-express-api

我正在尝试在我的Android应用程序中实现QPX请求。 我似乎无法找到任何有关如何在Android活动或按下按钮等内容的教程。

我在Java中发现了类似的东西,但我显然无法访问它在这里使用的所有类和对象:

/**
 * @param args
 */


private static final String APPLICATION_NAME = "MyFlightApplication";

private static final String API_KEY = "AIzaSyDnBCdsmTnrL5XFrO2TjJyvFioswjakNYU";

/** Global instance of the HTTP transport. */
private static HttpTransport httpTransport;

/** Global instance of the JSON factory. */
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();




public static void main() {
    // TODO Auto-generated method stub

    try {
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();


        PassengerCounts passengers= new PassengerCounts();
        passengers.setAdultCount(1);

        List<SliceInput> slices = new ArrayList<SliceInput>();

        SliceInput slice = new SliceInput();
        slice.setOrigin("NYC");
        slice.setDestination("LGA");
        slice.setDate("2017-06-29");
        slices.add(slice);

        TripOptionsRequest request= new TripOptionsRequest();
        request.setSolutions(10);
        request.setPassengers(passengers);
        request.setSlice(slices);

        TripsSearchRequest parameters = new TripsSearchRequest();
        parameters.setRequest(request);
        QPXExpress qpXExpress= new QPXExpress.Builder(httpTransport, JSON_FACTORY, null).setApplicationName(APPLICATION_NAME)
                .setGoogleClientRequestInitializer(new QPXExpressRequestInitializer(API_KEY)).build();

        TripsSearchResponse list= qpXExpress.trips().search(parameters).execute();
        List<TripOption> tripResults=list.getTrips().getTripOption();

        String id;

        for(int i=0; i<tripResults.size(); i++){
            //Trip Option ID
            id= tripResults.get(i).getId();
            System.out.println("id "+id);

            //Slice
            List<SliceInfo> sliceInfo= tripResults.get(i).getSlice();
            for(int j=0; j<sliceInfo.size(); j++){
                int duration= sliceInfo.get(j).getDuration();
                System.out.println("duration "+duration);
                List<SegmentInfo> segInfo= sliceInfo.get(j).getSegment();
                for(int k=0; k<segInfo.size(); k++){
                    String bookingCode= segInfo.get(k).getBookingCode();
                    System.out.println("bookingCode "+bookingCode);
                    FlightInfo flightInfo=segInfo.get(k).getFlight();
                    String flightNum= flightInfo.getNumber();
                    System.out.println("flightNum "+flightNum);
                    String flightCarrier= flightInfo.getCarrier();
                    System.out.println("flightCarrier "+flightCarrier);
                    List<LegInfo> leg=segInfo.get(k).getLeg();
                    for(int l=0; l<leg.size(); l++){
                        String aircraft= leg.get(l).getAircraft();
                        System.out.println("aircraft "+aircraft);
                        String arrivalTime= leg.get(l).getArrivalTime();
                        System.out.println("arrivalTime "+arrivalTime);
                        String departTime=leg.get(l).getDepartureTime();
                        System.out.println("departTime "+departTime);
                        String dest=leg.get(l).getDestination();
                        System.out.println("Destination "+dest);
                        String destTer= leg.get(l).getDestinationTerminal();
                        System.out.println("DestTer "+destTer);
                        String origin=leg.get(l).getOrigin();
                        System.out.println("origun "+origin);
                        String originTer=leg.get(l).getOriginTerminal();
                        System.out.println("OriginTer "+originTer);
                        int durationLeg= leg.get(l).getDuration();
                        System.out.println("durationleg "+durationLeg);
                        int mil= leg.get(l).getMileage();
                        System.out.println("Milleage "+mil);

                    }

                }
            }

            //Pricing
            List<PricingInfo> priceInfo= tripResults.get(i).getPricing();
            for(int p=0; p<priceInfo.size(); p++){
                String price= priceInfo.get(p).getSaleTotal();
                System.out.println("Price "+price);
            }

        }
        return;
    } catch (IOException e) {
        System.err.println(e.getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(1);

}

任何正确方向的帮助都会很棒。 这似乎是在正确的轨道上,但我不知道要改变什么以使其在Android Studio中运行。

0 个答案:

没有答案