Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

DwApiToken

pritaeas edited this page Jul 25, 2013 · 6 revisions

Class for API methods that require an access token.

Restrictions set by DaniWeb: all requests are cached, unless an access token is provided.

Exceptions

Read more about common exceptions.

Public class methods

__construct

Constructor.

Parameters

$accessToken  string  Access token (optional).

GetMailBoxTypes

Returns an alphabetically sorted list of supported mail box types, to be used as parameter in GetPrivateMessages.

Parameters

None

Return value

Array

- inbox
- outbox

GetPrivateMessages

Get private messages for the logged in user.

Parameters

$mailBoxType  string  Mail box type (required).

Exceptions

DwApiException  EX_ACCESS_TOKEN           Access token required.
DwApiException  EX_INVALID_TYPE_MAIL_BOX  Invalid mail box type.

Return value

string  JSON result.

See also

GetMailBoxTypes

GetVoteTypes

Returns an alphabetically sorted list of supported vote types, to be used as a parameter in VotePost.

Parameters

None

Return value

Array

- downvote
- upvote

GetWatchTypes

Returns an alphabetically sorted list of supported watch types, to be used as a filter in WatchArticle.

Parameters

None

Return value

Array

- unwatch
- watch

PostForumChat

Post a chat message to a forum's chat room.

Parameters

$forumId  int     Forum ID (required).
$message  string  Text message (required).

Exceptions

DwApiException  EX_ACCESS_TOKEN    Access token required.
DwApiException  EX_INVALID_INT     Invalid forum ID.
DwApiException  EX_INVALID_STRING  Empty text message.

Return value

string  JSON result.

PostMemberhat

Post a chat message to a member's shoutbox.

Parameters

$memberId  int     Member ID (required).
$message   string  Text message (required).

Exceptions

DwApiException  EX_ACCESS_TOKEN    Access token required.
DwApiException  EX_INVALID_INT     Invalid member ID.
DwApiException  EX_INVALID_STRING  Empty text message.

Return value

string  JSON result.

VotePost

Upvote or downvote a post.

Parameters

$postId  int     Post ID (required).
$upVote  string  Vote type (required).

Exceptions

DwApiException  EX_ACCESS_TOKEN       Access token required.
DwApiException  EX_INVALID_INT        Invalid post ID.
DwApiException  EX_INVALID_TYPE_VOTE  Invalid vote type.

Return value

string  JSON result.

See also

GetVoteTypes

WatchArticle

Watch or unwatch an article.

Parameters

$articleId  int     Article ID (required).
$watch      string  Watch type (required).

Exceptions

DwApiException  EX_ACCESS_TOKEN        Access token required.
DwApiException  EX_INVALID_INT         Invalid article ID.
DwApiException  EX_INVALID_TYPE_WATCH  Invalid watch type.

Return value

string  JSON result.

See also

GetWatchTypes

WhoAmI

Get the profile of the logged in user.

Parameters

None

Exceptions

DwApiException  EX_ACCESS_TOKEN  Access token required.

Return value

string  JSON result.

Code example

include 'DwApiToken.class.php';
$dwApi = new DwApiToken('YOUR_ACCESS_TOKEN_HERE');
try
{
    // get the watched articles of the logged in user (excluding Business Exchange articles)
    $articles = $dwapi->GetArticles(null, 'watching');

    $mailBoxTypes = $dwApi->GetMailBoxTypes();
    $inbox = $dwApi->GetPrivateMessages('inbox');
    $voteTypes = $dwApi->GetVoteTypes();
    $watchTypes = $dwApi->GetWatchTypes(); 
    $voteResult = $dwApi->VotePost(1867695, 'upvote');
    $watchResult = $dwApi->WatchArticle(435023, 'watch');
    $profile = $dwApi->WhoAmI();
}
catch (DwApiException $exception)
{
    die($exception->getMessage());
}