Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. function RetrieveData($account, $dataset, $kind, $apiToken)
  2. {
  3.  
  4. $port = "";
  5. if ($account === "localtest") {
  6. $port = ":8443";
  7. }
  8.  
  9. $requestURI = "https://" . $account . ".evergage.com" . $port . "/api/dataset/" . $dataset . "/" . $kind . ".json?_at=" . $apiToken;
  10.  
  11. debug_to_console("request URL: " . $requestURI);
  12.  
  13. $session = curl_init();
  14.  
  15. curl_setopt($session, CURLOPT_FAILONERROR, false);
  16. curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  17. curl_setopt($session, CURLOPT_FOLLOWLOCATION, false);
  18. curl_setopt($session, CURLOPT_HEADER, true);
  19. curl_setopt($session, CURLOPT_SSL_VERIFYHOST, false);
  20. curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
  21.  
  22.  
  23. $headers = array(
  24. 'Accept: application/json',
  25. 'Content-Type: application/json',
  26. );
  27.  
  28.  
  29. curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
  30. curl_setopt ($session, CURLOPT_CUSTOMREQUEST, "GET");
  31. curl_setopt($session, CURLOPT_URL, $requestURI);
  32.  
  33. // EVERYTHING RUNS FINE UP TO THIS POINT
  34.  
  35. set_time_limit(0);
  36. $response = curl_exec($session);
  37.  
  38. debug_to_console("success");
  39. echo 'Curl error: ' . curl_error($session);
  40.  
  41. $info = curl_getinfo($session);
  42.  
  43. $responseCode = $info["http_code"];
  44.  
  45. if ($responseCode >= 300) {
  46. print("Error loading data: " . $responseCode . "<br/>");
  47. print($response);
  48. } else {
  49. $body = substr($response, $info['header_size']);
  50. $decoded_result = json_decode($body, true);
  51. }
  52.  
  53. curl_close($session);
  54.  
  55. return $decoded_result;
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement