Difference between revisions of "API:User::get user name"
(New page: Get a user name of a user given a user id. ===Calling=== <code php>$api->user->get_username($user_id);</code> ===Parameters=== '''<nowiki>$</nowiki>user_id''' - An integer user ID corres...) |
m (→Output) |
||
Line 47: | Line 47: | ||
===Output=== | ===Output=== | ||
− | + | rrusczyk | |
1000000 is an invalid user id. | 1000000 is an invalid user id. |
Revision as of 13:05, 8 September 2018
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(1000000) . "
\n";
echo $api->user->get_username(1000001) . "
\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 1000000 is an invalid user id.