Google QPX Express API PHP

I am trying to use the QPX Express API for my site to search for flights.

https://developers.google.com/qpx-express/v1/requests#Examples

I have no idea how to run

curl -d @request.json --header "Content-Type: application/json" https://www.googleapis.com/qpxExpress/v1/trips/search?key=xxxxxxxxxxxxxx

from my php file. And how do I manage a json file. I want me to make a php file and set the type of the header, is it correct?

I could not find anything from outside

+4
source share
1 answer

JSON . JSON POST. , , PHP. , curl_init(), curl_setopt() curl_exec(). ...

$url = "https://www.googleapis.com/qpxExpress/v1/trips/search?key=YOUR_API_KEY_HERE";

$postData = '{
  "request": {
    "passengers": {
      "adultCount": 1
    },
    "slice": [
      {
        "origin": "BOS",
        "destination": "LAX",
        "date": "2016-05-10"
      },
      {
        "origin": "LAX",
        "destination": "BOS",
        "date": "2016-05-15"
      }
    ]
  }
}';

$curlConnection = curl_init();

curl_setopt($curlConnection, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($curlConnection, CURLOPT_URL, $url);
curl_setopt($curlConnection, CURLOPT_POST, TRUE);
curl_setopt($curlConnection, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curlConnection, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curlConnection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlConnection, CURLOPT_SSL_VERIFYPEER, FALSE);

$results = curl_exec($curlConnection);

, json_encode(), JSON.

$postData = array(
    "request" => array(
        "passengers" => array(
            "adultCount" => 1
        ),
        "slice" => array(
            array(
                "origin" => "BOS",
                "destination" => "LAX",
                "date" => "2016-05-10"
            ),
            array(
                "origin" => "LAX",
                "destination" => "BOS",
                "date" => "2016-05-15"
            )
        )
    )
);

curl_setopt($curlConnection, CURLOPT_POSTFIELDS, json_encode($postData));
+5

Source: https://habr.com/ru/post/1623782/


All Articles