API Main Page

Revision as of 01:33, 25 December 2008 by Levans (talk | contribs)
The AoPS API is a concept in development. It is not currently publicly accessible.

REST Interface

The API uses a REST-like interface. This means that our API method calls are made over the internet by sending HTTP GET or POST requests to the 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.

require_once 'AoPS.php'

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:

<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);

You may then call the API methods with:

</math>aops->api_client->method_name(paramer1, parameter2, ...);

A full sample program is provided below:

<?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 . '.';
}

This program would say hello to you and state your username. <source lang="text"> Hello Richard! Your username is rrusczk.