(→Usage) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | <noinclude>{{Trad|DE=Ryzom API/Charakter|EN=Ryzom API/Character|palette=api |H=1}}</noinclude> | ||
Access character information. | Access character information. | ||
Line 38: | Line 39: | ||
:On failure, function returns boolean false. | :On failure, function returns boolean false. | ||
− | <?php | + | :<syntaxhighlight lang="php"><?php |
− | require_once "ryzomapi_lite.php"; | + | require_once "ryzomapi_lite.php";</syntaxhighlight> |
:<syntaxhighlight lang="php">function info($char) { | :<syntaxhighlight lang="php">function info($char) { | ||
Line 51: | Line 52: | ||
echo "Character name: {$name}"; | echo "Character name: {$name}"; | ||
} | } | ||
− | } | + | }</syntaxhighlight> |
:<syntaxhighlight lang="php">$apikey = 'cABCDEF'; | :<syntaxhighlight lang="php">$apikey = 'cABCDEF'; | ||
Line 70: | Line 71: | ||
echo "Character API failed"; | echo "Character API failed"; | ||
}</syntaxhighlight> | }</syntaxhighlight> | ||
− | |||
− | |||
<noinclude>[[Category:Ryzom API|Character]]</noinclude> | <noinclude>[[Category:Ryzom API|Character]]</noinclude> |
Access character information.
<base URL>/character.php?apikey=key <base URL>/character.php?apikey[=key1&apikey[]=key2
<character> xml element has attributes *created* and *cached_until* (utc timestamp)
API is able to return information about multiple characters at once and so each <character> element is child of <ryzomapi> root element:
<ryzomapi>
<character apikey="key1" created="1387369332" modules="C01:P01" cached_until="1387369632">
....
</character>
<character apikey="key2" created="1387369332" modules="P01" cached_until="1387369632">
....
</character>
</ryzomapi>
Invalid key error:
<character apikey="key1" created="1387369873">
<error code="404">invalid key</error>
</character>
Possible error codes are listed on API error codes.
ryzom_character_api($apikey)
<?php
require_once "ryzomapi_lite.php";
function info($char) {
if (isset($char->error)) {
$apikey = htmlspecialchars($char['apikey']);
$error = htmlspecialchars($char->error);
$code = (int)$char->error['code'];
echo "Character API key '{$apikey}' failed: {$code}:{$error}";
} else {
$name = htmlspecialchars($char->name);
echo "Character name: {$name}";
}
}
$apikey = 'cABCDEF';
$chars = ryzom_character_api($apikey);
if ($chars !== false) {
info($chars[$apikey]);
} else {
echo "Character API failed";
}
$apikeys = ['cABCDEF', 'c123456'];
$chars = ryzom_character_api($apikeys);
if ($chars !== false) {
foreach($chars as $char) {
info($char);
}
} else {
echo "Character API failed";
}