Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $url = 'https://login.salesforce.com/services/oauth2/token';
- //$url = 'https://test.salesforce.com/services/oauth2/token';
- $client_id = get_option('hnsf_client_id', true);
- $client_secret = get_option('hnsf_client_secret', true);
- $username = get_option('hnsf_username', true);
- $password = get_option('hnsf_password', true);
- $security_token = get_option('hnsf_security_token', true);
- $params = "grant_type=password"
- . "&client_id=" . $client_id
- . "&client_secret=" . $client_secret
- . "&username=" . $username
- . "&password=". $password; // Security token removed for production (per Kritika) // $password . $security_token
- $curl = curl_init($url);
- curl_setopt($curl, CURLOPT_HEADER, false);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
- $json_response = curl_exec($curl);
- $response = json_decode($json_response, true);
- if( ! isset( $response['error'] ) ) {
- update_option('hnsf_access_token', $response['access_token']);
- update_option('hnsf_instance_url', $response['instance_url']);
- } else {
- die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
- }
- return $response;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement