Watson Campaign Automation OAuth tokens have a lifetime of 4 hours, but tokens can be refreshed after 3 hours. If you request before the start of the fourth hour, you receive the same access token that you obtained earlier. If you request after the start of the third hour, a new access token is granted. The user account is going to have two access tokens available to them to use (the first token expires in 1 hour and the second token expires in 4 hours. Request a new token after 3 hours to avoid the unexpected expiration of a single access token.
Examples of code to create an OAuth access token by using PHP.
#!/usr/bin/php <?php $host = 'http://engage.com/oauth/token'; $key = 'XMLAPIENGAGE'; $secret = 'PRODUCTION_USE'; $refreshToken = 'ac1bfab0-f310-4161-9f6b-53cabac451a8'; $fields = array( 'client_id' => $key, 'client_secret' => $secret, 'refresh_token' => $refreshToken, 'grant_type' => 'refresh_token' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $host); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields)); $json_result = curl_exec($ch); $result = json_decode($json_result); var_dump($result); ?>