小编Akr*_*ram的帖子

如何使用Google QPX API和Java进行航班搜索?

我正在尝试构建一个简单的Java代码,使用Google QPX API获取从纽约到伦敦的航班.我注册了Google并获得了API_key.

我阅读了文档,但不幸的是,我找不到任何能告诉我如何操作的例子.

这是我到目前为止所尝试的:

import com.google.api.services.qpxExpress.model.*;
import java.util.*;

public class Main 
{
    public static void main(String[] args) 
    {   
        // Passengers
        PassengerCounts passengers = new PassengerCounts();
        passengers.setAdultCount(2);

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

        SliceInput slice = new SliceInput();
        slice.setOrigin("JFK"); // John Kennedy Airport in Ney York
        slice.setDestination("LHR"); // London Heathrow
        slice.setDate("2015-07-01");
        slices.add(slice);


        // Options request
        TripOptionsRequest tripOptions = new TripOptionsRequest(); 
        tripOptions.setPassengers(passengers);
        tripOptions.setSlice(slices);


        // Search request
        TripsSearchRequest tripSearchReq = new TripsSearchRequest();
        tripSearchReq.setRequest(tripOptions);

        // Next steps?
        // Setting up QPXExpress?

    } …
Run Code Online (Sandbox Code Playgroud)

api google-api httprequest google-api-java-client

6
推荐指数
1
解决办法
2886
查看次数