fork download
  1. <?php
  2.  
  3. /** Set up `curl` to make authenticated API requests */
  4. $curl = curl_init();
  5.  
  6. CURLOPT_URL => "https://a...content-available-to-author-only...s.com/properties",
  7. CURLOPT_RETURNTRANSFER => true,
  8. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  9. CURLOPT_CUSTOMREQUEST => "GET",
  10. CURLOPT_HTTPHEADER =>
  11. "Authorization: Basic '" . base64_encode('simplyrets:simplyrets') . "'",
  12. ),
  13. ));
  14.  
  15. /**
  16.  * 1. Execute the request
  17.  * 2. Check for errors
  18.  * 3. Close the connection
  19.  */
  20. $response = curl_exec($curl);
  21. $err = curl_error($curl);
  22. curl_close($curl);
  23.  
  24. if ($err) {
  25. echo "cURL Error #:" . $err;
  26. }
  27.  
  28. /** Decode JSON response - this is a list of listings */
  29. $json_response = json_decode($response);
  30.  
  31. /** Print address and list price of the first listing */
  32. echo "<h2>" . $json_response[0]->address->full . "</h2>";
  33. echo "<p>List price: " . $json_response[0]->listPrice . "</p>";
  34.  
  35. ?>
Success #stdin #stdout #stderr 0.04s 25816KB
stdin
Standard input is empty
stdout
cURL Error #:Could not resolve host: api.simplyrets.com<h2></h2><p>List price: </p>
stderr
PHP Notice:  Trying to get property 'address' of non-object in /home/fq255p/prog.php on line 34
PHP Notice:  Trying to get property 'full' of non-object in /home/fq255p/prog.php on line 34
PHP Notice:  Trying to get property 'listPrice' of non-object in /home/fq255p/prog.php on line 35