|
|
(4 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
− | ==REST Interface==
| + | This page has been migrated to https://artofproblemsolving.com/wiki/index.php/API:Introduction |
− | The API uses a [[Wikipedia:Representational State Transfer|REST]]-like interface. This means that our API method calls are made over the internet by sending HTTP GET or POST requests to the [http://www.artofproblemsolving.com/API/Server/restserver.php AoPS API REST server] . Nearly any computer language can be used to communicate over HTTP with the REST server, provided a language specific library or the use of direct JSON data being transmitted to the server.
| |
− | | |
− | ==API==
| |
− | ;[[user.getusername]]
| |
− | :Get the username of the active user or by user id
| |
− | ;[[user.getfirstname]]
| |
− | :Get first name of the active user or by user id
| |
− | | |
− | | |
− | ==PHP Specific==
| |
− | To utilize the AoPS API, you will need to download AoPS.php and AoPS_API_PHP5_Rest.php. These can be placed anywhere on your web server so that they can be access through PHP.
| |
− | | |
− | You should include AoPS.php on every page of your application which requires the AoPS API functionality. The include must come before any API calls.
| |
− | <source lang="php">
| |
− | require_once 'AoPS.php'
| |
− | </source>
| |
− | | |
− | You will need to create an instance of the AoPS API object by including the following code in your application, prior to calling any API method:
| |
− | <source lang="php">
| |
− | <math>api_key = '<insert your assigned API key here>';
| |
− | </math>secret_key = '<insert your assigned Secret key here>';
| |
− | <math>aops = new AoPS(</math>api_key, <math>secret_key);
| |
− | </source>
| |
− | | |
− | You may then call the API methods with:
| |
− | <source lang="php">
| |
− | </math>aops->api_client->method_name(paramer1, parameter2, ...);
| |
− | </source>
| |
− | | |
− | A full sample program is provided below:
| |
− | <source lang="php">
| |
− | <?php
| |
− | require_once 'AoPS.php';
| |
− | | |
− | <math>api_key = 'abcdefghijklmnopqrstuvwxyz123456';
| |
− | </math>secret_key = 'abcdefghijklmnopqrstuvwxyz123456';
| |
− | <math>aops = new AoPS(</math>api_key, <math>secret_key);
| |
− | | |
− | </math>username = <math>aops->api_client->user_get_username();
| |
− | </math>firstname = <math>aops->api_client->user_get_firstname();
| |
− | if (</math>username === FALSE || <math>firstname === FALSE)
| |
− | {
| |
− | echo 'Invalid user';
| |
− | }
| |
− | else
| |
− | {
| |
− | echo 'Hello ' . </math>firstname . '! Your username is ' . $username . '.';
| |
− | }
| |
− | </source>
| |
− | This program would say hello to you and state your username.
| |
− | <source lang="text">
| |
− | Hello Richard! Your username is rrusczk.
| |