Difference between revisions of "Ryzom API/Character"

From EncyclopAtys

Jump to: navigation, search
(Created page with " Character Access character information. Base URL /character.php?apikey=key /character.php?apikey[]=key1&apikey[]=key2 URL Parameters apikey Character API key...")
 
 
(6 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>
Character
 
 
 
 
Access character information.
 
Access character information.
Base URL
 
  
    /character.php?apikey=key
+
===Usage===
    /character.php?apikey[]=key1&apikey[]=key2
+
<base URL>/character.php?apikey=key
 +
<base URL>/character.php?apikey[=key1&apikey[]=key2
  
URL Parameters
+
====URL Parameters====
 
+
;apikey:
apikey
+
:Character API key starting with 'c'
    Character API key starting with 'c'
 
 
 
Cache Duration
 
  
 +
====Cache Duration ====
 
<character> xml element has attributes *created* and *cached_until* (utc timestamp)
 
<character> xml element has attributes *created* and *cached_until* (utc timestamp)
XML structure
 
  
API is able to return information about multiple characters at once and so each <character> element is child of <ryzomapi> root element
+
==== XML structure ====
  
<ryzomapi>
+
API is able to return information about multiple characters at once and so each <character> element is child of <ryzomapi> root element:
 +
:<syntaxhighlight lang="xml"><ryzomapi>
 
   <character apikey="key1" created="1387369332" modules="C01:P01" cached_until="1387369632">
 
   <character apikey="key1" created="1387369332" modules="C01:P01" cached_until="1387369632">
 
     ....
 
     ....
Line 27: Line 23:
 
     ....
 
     ....
 
   </character>
 
   </character>
</ryzomapi>
+
</ryzomapi></syntaxhighlight>
               
+
             
 
+
Invalid key error:
Invalid key error
+
:<syntaxhighlight lang="xml"><character apikey="key1" created="1387369873">
 
 
<character apikey="key1" created="1387369873">
 
 
   <error code="404">invalid key</error>
 
   <error code="404">invalid key</error>
</character>
+
</character></syntaxhighlight>
               
+
Possible error codes are listed on [[Ryzom API#API error codes|API error codes]].
 
 
Possible error codes are listed on API error codes.
 
PHP interface
 
 
 
ryzom_character_api($apikey)
 
  
$apikey can be either string (single key) or array of strings.
+
=== PHP interface ===
  
On success, function returns associative array of SimpleXMLElement with apikey as array index.
+
ryzom_character_api($apikey)
  
On failure, function returns boolean false.
+
::$apikey can be either string (single key) or array of strings.
 +
:On success, function returns associative array of SimpleXMLElement with apikey as array index.
 +
:On failure, function returns boolean false.
  
<?php
+
:<syntaxhighlight lang="php"><?php
require_once "ryzomapi_lite.php";
+
require_once "ryzomapi_lite.php";</syntaxhighlight>
  
function info($char) {
+
:<syntaxhighlight lang="php">function info($char) {
 
   if (isset($char->error)) {
 
   if (isset($char->error)) {
 
     $apikey = htmlspecialchars($char['apikey']);
 
     $apikey = htmlspecialchars($char['apikey']);
Line 61: Line 52:
 
     echo "Character name: {$name}";
 
     echo "Character name: {$name}";
 
   }
 
   }
}
+
}</syntaxhighlight>
  
$apikey = 'cABCDEF';
+
:<syntaxhighlight lang="php">$apikey = 'cABCDEF';
 
$chars = ryzom_character_api($apikey);
 
$chars = ryzom_character_api($apikey);
 
if ($chars !== false) {
 
if ($chars !== false) {
Line 69: Line 60:
 
} else {
 
} else {
 
   echo "Character API failed";
 
   echo "Character API failed";
}
+
}</syntaxhighlight>
  
$apikeys = ['cABCDEF', 'c123456'];
+
:<syntaxhighlight lang="php">$apikeys = ['cABCDEF', 'c123456'];
 
$chars = ryzom_character_api($apikeys);
 
$chars = ryzom_character_api($apikeys);
 
if ($chars !== false) {
 
if ($chars !== false) {
Line 79: Line 70:
 
} else {
 
} else {
 
   echo "Character API failed";
 
   echo "Character API failed";
}
+
}</syntaxhighlight>
               
+
<noinclude>[[Category:Ryzom API|Character]]</noinclude>
 
 
<noinclude>[[Category:Ryzom API]]</noinclude>
 

Latest revision as of 11:32, 27 May 2023

de:Ryzom API/Charakter en:Ryzom API/Character
 
UnderConstruction.png
Translation to review
Don't blame the contributors, but come and help them 😎

Reference text ( Maintained text, used as reference ) :
Notes: (Leda, 2023-05-27)

Access character information.

Usage

<base URL>/character.php?apikey=key
<base URL>/character.php?apikey[=key1&apikey[]=key2

URL Parameters

apikey
Character API key starting with 'c'

Cache Duration

<character> xml element has attributes *created* and *cached_until* (utc timestamp)

XML structure

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.

PHP interface

ryzom_character_api($apikey)
$apikey can be either string (single key) or array of strings.
On success, function returns associative array of SimpleXMLElement with apikey as array index.
On failure, function returns boolean false.
<?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";
}