Guest User

Untitled

a guest
Nov 18th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. <?php
  2. $data = array("grant_type" => "password", "client_id" => "*********************************","client_secret"=>"************","username" =>"*********","password" => "**************");
  3. $data_string = json_encode($data);
  4. $url='https://login.salesforce.com/services/oauth2/token';
  5. $ch = curl_init('https://login.salesforce.com/services/oauth2/token');
  6.  
  7. curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
  8. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  9. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  10. curl_setopt($ch, CURLOPT_HEADER,true);
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
  12. curl_setopt($ch,CURLOPT_VERBOSE,true);
  13. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  14. 'Content-Type: application/json',
  15. 'Content-Length: ' . strlen($data_string))
  16. );
  17.  
  18. $result = curl_exec($ch);
  19.  
  20. if($result === false)
  21. {
  22. echo 'Curl error: ' . curl_error($ch);
  23. }
  24. else
  25. {
  26. echo 'Operation completed without any errors';
  27. }
  28.  
  29.  
  30. $info = curl_getinfo($ch);
  31. echo curl_getinfo($ch);
  32. echo $info['access_token'];
  33. echo curl_getinfo($ch, CURLINFO_HTTP_CODE);
  34. curl_close($ch);
  35.  
  36. $result1= file_get_contents($url);
  37. var_dump(json_decode($result1, true));
  38. }
  39.  
  40. ?>
  41.  
  42. <?php
  43. require_once 'configPWFlow.php';
  44.  
  45. session_start();
  46.  
  47. $token_url = LOGIN_URI . "/services/oauth2/token";
  48.  
  49.  
  50. $params = "grant_type=password"
  51. . "&client_id=" . CLIENT_ID
  52. . "&client_secret=" . CLIENT_SECRET
  53. . "&username=" . USERNAME
  54. . "&password=" . PASSWORD;
  55.  
  56. $curl = curl_init($token_url);
  57. curl_setopt($curl, CURLOPT_HEADER, false);
  58. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  59. curl_setopt($curl, CURLOPT_POST, true);
  60. curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
  61.  
  62. $json_response = curl_exec($curl);
  63. ...
  64. ?>
Add Comment
Please, Sign In to add comment