I am trying (for learning purpose) to get a specific Real-Time Bus Predictions from the API of Washington Metropolitan Area; https://developer.wmata.com and Real-Time Bus Predictions
Bus Stop ID: 3001954
Api Key: This is a Demo Api Key that can be use for demo: e13626d03d8e4c03ac07f95541b3091b Source: https://developer.wmata.com/demokey
I am trying to use their PHP JSON example code, but nothing is happing. I am missing something? Any suggestions please? Thank you so much in advance for your help.
<?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';
$request = new Http_Request2('https://api.wmata.com/NextBusService.svc/json/jPredictions');
$url = $request->getUrl();
$headers = array(
// Request headers
'api_key' => 'e13626d03d8e4c03ac07f95541b3091b',
);
$request->setHeader($headers);
$parameters = array(
// Request parameters
'StopID' => '3001954',
);
$url->setQueryVariables($parameters);
$request->setMethod(HTTP_Request2::METHOD_GET);
// Request body
$request->setBody("{body}");
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>
Maybe I am missing something here? $request->setBody("{body}");