Advertisement
Guest User

Untitled

a guest
Apr 14th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. Fatal error: Uncaught exception 'Exception' with message 'We did not get a HTTP 200 when retrieving a ticket. We recieved this: { "url": "https://api.adform.com/Services/Security/Login", "content_type": null, "http_code": 0, "header_size": 0, "request_size": 0, "filetime": -1, "ssl_verify_result": 1, "redirect_count": 0, "total_time": 0.187, "namelookup_time": 0.14, "connect_time": 0.156, "pretransfer_time": 0, "size_upload": 0, "size_download": 0, "speed_download": 0, "speed_upload": 0, "download_content_length": -1, "upload_content_length": -1, "starttransfer_time": 0, "redirect_time": 0, "redirect_url": "", "primary_ip": "37.157.5.109", "certinfo": [], "primary_port": 443, "local_ip": "192.168.1.7", "local_port": 49460 }false' in C:UsersMikkelPHPadformdspadf-ticket.php:60 Stack trace: #0 C:UsersMikkelPHPadformdspadf-ticket.php(66): Adform->ticket() #1 {main} thrown in C:UsersMikkelPHPadformdspadf-ticket.php on line 60
  2.  
  3. <?php
  4.  
  5. class Adform
  6. {
  7. protected $user;
  8. protected $pass;
  9.  
  10. public function __construct($user, $pass)
  11. {
  12. $this->user = $user;
  13. $this->pass = $pass;
  14. }
  15.  
  16. # Authenticate to Adform by retrieving a ticket
  17. public function ticket()
  18. {
  19. $curl = curl_init();
  20.  
  21. $credentials = json_encode(array(
  22. 'UserName' => $this->user,
  23. 'Password' => $this->pass
  24. ));
  25.  
  26. $options = array(
  27. CURLOPT_URL => 'https://api.adform.com/Services/Security/Login',
  28. CURLOPT_CUSTOMREQUEST => 'POST',
  29. CURLOPT_POSTFIELDS => $credentials,
  30. CURLOPT_HEADER => TRUE,
  31. CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
  32. CURLOPT_RETURNTRANSFER => TRUE,
  33. );
  34.  
  35. curl_setopt_array($curl, $options);
  36.  
  37. $result = curl_exec($curl);
  38.  
  39. if(curl_getinfo($curl, CURLINFO_HTTP_CODE) == '200')
  40. {
  41. $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
  42. $header = substr($result, 0, $header_size);
  43. $body = json_decode(substr($result, $header_size), TRUE);
  44.  
  45. curl_close($curl);
  46.  
  47. if(array_key_exists('Ticket', $body))
  48. {
  49. # We successfully retrieved a ticket!
  50. return $body['Ticket'];
  51. }
  52. else
  53. {
  54. # We connected to Adforms server but did not get a ticket..
  55. throw new Exception('We connected to Adforms server but did not retrieve a ticket. We recieved this: ' . $result);
  56. }
  57.  
  58. }
  59. else
  60. {
  61. #We did not get a HTTP 200 from the request to Adform..
  62. throw new Exception('We did not get a HTTP 200 when retrieving a ticket. We recieved this: ' . json_encode(curl_getinfo($curl), JSON_PRETTY_PRINT) . json_encode($result, JSON_PRETTY_PRINT));
  63. }
  64. }
  65. }
  66.  
  67. $adform = new Adform("notsharing","thatwithyouguys");
  68. echo $adform->ticket();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement