API:User::get user name

Revision as of 16:25, 28 May 2009 by Levans (talk | contribs) (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...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

rruszyk
1000000 is an invalid user id.