Advertisement
josh401

SF Integration Example

Aug 4th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. $url = 'https://login.salesforce.com/services/oauth2/token';
  2. //$url = 'https://test.salesforce.com/services/oauth2/token';
  3. $client_id = get_option('hnsf_client_id', true);
  4. $client_secret = get_option('hnsf_client_secret', true);
  5. $username = get_option('hnsf_username', true);
  6. $password = get_option('hnsf_password', true);
  7. $security_token = get_option('hnsf_security_token', true);
  8.            
  9. $params = "grant_type=password"
  10.         . "&client_id=" . $client_id
  11.         . "&client_secret=" . $client_secret
  12.         . "&username=" . $username
  13.         . "&password=". $password;  // Security token removed for production (per Kritika) // $password . $security_token
  14.        
  15. $curl = curl_init($url);
  16. curl_setopt($curl, CURLOPT_HEADER, false);
  17. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  18. curl_setopt($curl, CURLOPT_POST, true);
  19. curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
  20.        
  21. $json_response = curl_exec($curl);
  22. $response = json_decode($json_response, true);
  23.            
  24. if( ! isset( $response['error'] ) ) {
  25.     update_option('hnsf_access_token', $response['access_token']);
  26.     update_option('hnsf_instance_url', $response['instance_url']);
  27. } else {
  28.     die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
  29. }
  30.  
  31. return $response;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement