API:User::get user name
Get a user name of a user given a user id.
Calling
$api->user->get_username($user_id);
Parameters
$user_id - An integer user ID corresponding to the user ID used on artofproblemsolving.com
Returns
The user name associated with the user id.
Exceptions
AoPSAPI_Exception::MISSING_PARAMETER - Missing User ID
AoPSAPI_Exception::INVALID_PARAMETER - Invalid parameter. Triggered when there are non-numeric characters in user id parameter
AoPSAPI_Exception::INVALID_USER - User not found in Art of Problem Solving database
Example
require_once 'AoPSAPI.php';
$api = new AoPSAPI('<api_key>', '<secret_key>');
try
{
echo $api->user->get_username(1163) . "
\n";
echo $api->user->get_username(5000000) . "
\n";
echo $api->user->get_username(5000001) . "
\n";
}
catch (AoPSAPI_Exception $ex)
{
switch ( $ex->getCode() )
{
case AoPSAPI_Exception::MISSING_PARAMETER:
echo "I should never be seen since the API sends in correct parameters.
\n";
break;
case AoPSAPI_Exception::INVALID_PARAMETER:
echo "Oh no, I sent in the wrong parameter " . implode(" ", $ex->getParams()) . ".
\n";
break;
case AoPSAPI_Exception::INVALID_USER:
echo implode(" ", $ex->getParams()) . " is an invalid user id.
\n";
break;
default:
echo $ex->getMessage() . "
\n";
break;
}
}
Output
rrusczyk 5000000 is an invalid user id.