DwApiToken
Class for API methods that require an access token.
Restrictions set by DaniWeb: all requests are cached, unless an access token is provided.
Read more about common exceptions.
Constructor.
Parameters
$accessToken string Access token (optional).
Returns an alphabetically sorted list of supported mail box types, to be used as parameter in GetPrivateMessages.
Parameters
None
Return value
Array
- inbox
- outbox
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
Returns an alphabetically sorted list of supported vote types, to be used as a parameter in VotePost.
Parameters
None
Return value
Array
- downvote
- upvote
Returns an alphabetically sorted list of supported watch types, to be used as a filter in WatchArticle.
Parameters
None
Return value
Array
- unwatch
- watch
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.
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.
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
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
Get the profile of the logged in user.
Parameters
None
Exceptions
DwApiException EX_ACCESS_TOKEN Access token required.
Return value
string JSON result.
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());
}