This code has been developed and maintained by MXit Lifestyle. It is released under the Apache License, Version 2.0
Creates an interface to the MXit API using your Client Id that was assigned to your application in your dashboard at http://code.mxit.com
key: string
$key = 'f00df00df00df00df00df00df00df00d';
$secret = 'f00df00df00df00df00df00df00df00d';
$api = new MxitAPI($key, $secret);
Requests a user to provide specific MXit permissions to your application.
Once the user grants access, it redirects back to: redirect_uri/cb?code=f00df00df00df00df00df00df00df00d Eg: http://www.example.com/cb?code=f00df00df00df00df00df00df00df00d
Where the value of code (f00df00df00df00df00df00df00df00d in this example) is used to request the OAuth2 access token, in the get_user_token() method.
NOTE: The access token is only valid for 3600 seconds.
redirect_uri: string
scope: string
state: string (optional)
None
$api->request_access('http://www.example.com', 'profile/public');
Gets an OAuth2 token for a user once they have granted permissions to an application.
The request_access() method must be called, before this method is called. This method processes the code returned from request_access() and obtains an OAuth2 token.
NOTE: The redirect URI specified in the get_user_token() method must match the redirect URI specified in the request_access() method, otherwise the OAuth2 server will not grant you a valid OAuth2 token.
code: string
redirect_uri: string
None
$api->get_user_token('f00df00df00df00df00df00df00df00d', 'http://www.example.com/');
Gets an OAuth2 token for an application rather than for a user. This is used for the MXit messaging API - see the send_message() method.
scope: string
None
$api->get_app_token('message/send');
Gets OAuth2 token detail and returns it as an array. Useful for storing the detail in a Session.
None
ARRAY
$token = $api->get_token();
$_SESSION['token'] = $token;
Sets OAuth2 token detail from an array. Useful for setting the OAuth2 token detail from a Session.
detail: array
None
$token = $_SESSION['token'];
$api->set_token($token);
Although some methods in the API allow information to be retrieved using a user's login, other information can only be retrieved using the user's mxitid. This method gets the user's mxitid from their login.
login: string
STRING
$login = 'foobarbaz';
$api->get_app_token('profile/public');
$user_id = $api->get_user_id($login);
Gets the status message for a user
login: string
STRING
$login = 'foobarbaz';
$api->get_app_token('profile/public');
$status = $api->get_status($login);
Gets the avatar image of a user. The content_type from the API can be useful for determining the image format.
login: string
BINARY
$login = 'foobarbaz';
$api->get_app_token('profile/public');
$avatar = $api->get_avatar($login);
$content_type = $api->content_type;
Gets the display name (nickname) of a user.
login: string
STRING
$login = 'foobarbaz';
$api->get_app_token('profile/public');
$display_name = $api->get_display_name($login);
Gets the basic profile information for the userid
mxitid: string
OBJECT
$login = 'foobarbaz';
$api->get_app_token('profile/public');
$user_id = $api->get_user_id($login);
$profile = $api->get_basic_profile($user_id);
Send a message.
From: string
To: string
Message: string
Contains Markup: string
None
$api->get_app_token('message/send');
$api->send_message('foobarbaz', 'm11111111111', 'test message', 'true');
Gets the full profile information (including email address and phone number) for the userid in the access token.
None
OBJECT
$api->request_access('http://www.example.com', 'profile/private');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$profile = $api->get_full_profile();
Updates the profile information for the userid in the access token.
Data: array
OBJECT
$api->request_access('http://www.example.com', 'profile/write');
$data = array('FirstName' => 'Joe',
'LastName' => 'Soap',
'Title' => 'Mr',
'DisplayName' => 'Zeus',
'Gender' => 0,
'RelationshipStatus' => 0,
'WhereAmI' => 'Cape Town',
'AboutMe' => 'Friendly',
'Email' => 'hello@example.com',
'MobileNumber' => '0715555555');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$profile = $api->update_profile($data);
Subscribes the userid contained in the access token, to the service or sends an invite to another user. If the contact is a Service, then the service is added and accepted. If the contact is a MXitId, then an invite is sent to the other user.
None
None
$api->request_access('http://www.example.com', 'contact/invite');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$api->add_contact('hangingman');
Gets the list of contacts for the userid contained in the access token.
ContactTypes: string (optional)
Skip: integer (optional)
Count: integer (optional)
OBJECT
$api->request_access('http://www.example.com', 'graph/read');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$contacts = $api->get_contact_list('@Apps', 0, 2);
Gets a list of suggested friends for the userid contained in the access token.
None
OBJECT
$api->request_access('http://www.example.com', 'graph/read');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$contacts = $api->get_friend_suggestions();
Set the status message for the userid contained in the access token.
Status Message
None
$api->request_access('http://www.example.com', 'status/write');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$api->set_status('test status');
Upload an avatar image for the userid contained in the access token.
Image: binary data
Mime Type: string
None
$api->request_access('http://www.example.com', 'avatar/write');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$avatar = file_get_contents('/Users/ashley/Pictures/goblin.jpg');
$api->set_avatar($avatar, 'image/jpeg');
Delete the avatar image for the userid contained in the access token.
None
None
$api->request_access('http://www.example.com', 'avatar/write');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$api->delete_avatar();
List gallery folders for the userid contained in the access token.
None
OBJECT
$api->request_access('http://www.example.com', 'content/read');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$folders = $api->list_gallery_folders();
List the items in a specific gallery folder for the userid contained in the access token.
Folder: string
Skip: integer (optional)
Count: integer (optional)
OBJECT
$api->request_access('http://www.example.com', 'content/read');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$items = $api->list_gallery_items('Default');
Create a new gallery folder for the userid contained in the access token.
Folder: string
None
$api->request_access('http://www.example.com', 'content/write');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$api->create_gallery_folder('Foo');
Rename a new gallery folder for the userid contained in the access token.
Source: string
Destination: string
None
$api->request_access('http://www.example.com', 'content/write');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$api->rename_gallery_folder('Foo', 'Bar');
Delete a new gallery folder for the userid contained in the access token.
Folder: string
None
$api->request_access('http://www.example.com', 'content/write');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$api->delete_gallery_folder('Bar');
Download an image from a gallery folder for the userid contained in the access token.
FileId: string
BINARY
$api->request_access('http://www.example.com', 'content/read');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$image = $api->download_gallery_image('f00df00d-f00d-f00d-f00d-f00df00df00d');
$content_type = $api->content_type;
Upload an image to a gallery folder for the userid contained in the access token.
Folder: string
File Name: string
Mime Type: string
Image: binary data
None
$api->request_access('http://www.example.com', 'content/write');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$image = file_get_contents('/Users/ashley/Pictures/profile.jpg');
$api->upload_gallery_image('Default', 'profile.jpg', 'image/jpeg', $image);
Rename an image in a gallery folder for the userid contained in the access token.
File Id: string
Destination: string
None
$api->request_access('http://www.example.com', 'content/write');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$api->rename_gallery_image('f00df00d-f00d-f00d-f00d-f00df00df00d', 'Renamed Image');
Delete an image from a gallery folder for the userid contained in the access token.
File Id: string
None
$api->request_access('http://www.example.com', 'content/write');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$api->delete_gallery_image('f00df00d-f00d-f00d-f00d-f00df00df00d');
Send a file to a user
User Id: string
File Name: string
Mime Type: string
Data: binary data
None
$api->request_access('http://www.example.com', 'content/send');
$api->get_user_token($_GET['code'], 'http://www.example.com');
$image = file_get_contents('/Users/ashley/Pictures/profile.jpg');
$api->send_file('m123456789, 'profile.jpg', 'image/jpeg', $image);