1.11M Members

Documentation

RSS Feeds

Options Usage
  • Forum ID # (Optional)
    • Any valid Forum ID #
  • Article Type (Optional)
    • unanswered
    • solved
    • news
    • reviews
    • interviews
    • tutorials
    • code
    • whitepapers

http://www.daniweb.com/rss/pull/{FORUM ID #}
http://www.daniweb.com/rss/pull/{ARTICLE TYPE}
http://www.daniweb.com/rss/pull/{FORUM ID #}/{ARTICLE TYPE}

<?php
$feed = file_get_contents('http://www.daniweb.com/rss/pull/solved');
$articles = new SimpleXMLElement($feed);
foreach ($articles->channel->item as $article) {
    echo '<a href="' . $article->link . '">' . $article->title . '</a><br />';
}
?>

RESTful Requests that return JSON / JSONP

  • All requests return JSON by default. You can pass in the query string ?callback={CALLBACK} to return JSONP instead.
  • JSONP should be used for Javascript requests as a workaround to Javascript's same-origin policy against fetching data across domains.
  • All unauthenticated requests are heavily cached. You can pass in an access token to retrieve non-cached results.
  • Invalid requests will return an HTTP 400 error when JSON is requested, and a wrapped JSON error message when JSONP is requested.
  • {:ID} is used to represent any valid ID #. {:IDS} indicates that a semicolon-delimited list of multiple ID #s is additionally acceptable.
  • Query string parameters only available under limited conditions will indicate the acceptable URIs within the Sample Usage table below.

Fetch Forums

Parameters Sample Usage
GET Parameters:
  • include_self (Optional, Default false)
    • true
    • false

http://www.daniweb.com/api/forums
http://www.daniweb.com/api/forums/children?include_self=
http://www.daniweb.com/api/forums/descendants?include_self=
http://www.daniweb.com/api/forums/{:IDS}
http://www.daniweb.com/api/forums/{:IDS}/ancestors?include_self=
http://www.daniweb.com/api/forums/{:IDS}/children?include_self=
http://www.daniweb.com/api/forums/{:IDS}/descendants?include_self=

<?php
// Fetch a nested hierarchy of forums and sub-forums
//    within the Software Development category
$output = json_decode(file_get_contents(
    'http://www.daniweb.com/api/forums/2'));
var_dump($output);
?>

Sample Data

Fetch Articles

Parameters Sample Usage
GET Parameters:
  • filter (Optional)
    • unanswered
    • solved
    • threads
    • news
    • reviews
    • interviews
    • tutorials
    • code
    • whitepapers
  • orderby (Optional, Default lastpost)
    • firstpost
    • lastpost
  • page (Optional, Default 1)
    • Any valid Page #
  • forum_id (Optional)
    • Any valid Forum ID #

http://www.daniweb.com/api/articles
http://www.daniweb.com/api/articles/{:IDS}
http://www.daniweb.com/api/forums/{:IDS}/articles
http://www.daniweb.com/api/members/{:IDS}/articles?forum_id=

<?php
// Fetch articles started by Dani that have been marked solved
$output = json_decode(file_get_contents(
    'http://www.daniweb.com/api/members/1/articles?filter=solved'));
var_dump($output);
?>

Sample Data

Fetch Posts

Parameters Sample Usage
GET Parameters:
  • page (Optional, Default 1)
    • Any valid Page #
  • filter (Optional)
    • solved
    • upvoted
    • downvoted

http://www.daniweb.com/api/posts
http://www.daniweb.com/api/posts/{:IDS}
http://www.daniweb.com/api/articles/{:ID}/posts
http://www.daniweb.com/api/forums/{:ID}/posts
http://www.daniweb.com/api/members/{:ID}/posts?filter=

Sample Data

Fetch Members

Parameters Sample Usage
GET Parameters:
  • username (Optional)
    • Any valid Member Username
  • page (Optional, Default 1)
    • Any valid Page #

http://www.daniweb.com/api/members?username=
http://www.daniweb.com/api/members?page=
http://www.daniweb.com/api/members/{:IDS}?page=

Sample Data

Fetch Member Endorsements

Parameters Sample Usage
GET Parameters:
  • None

http://www.daniweb.com/api/members/{:ID}/endorsements

Sample Data

Fetch Activity Points

Parameters Sample Usage
GET Parameters:
  • None

http://www.daniweb.com/api/members/{:ID}/activities

Sample Data

Fetch Reputation Comments

Parameters Sample Usage
GET Parameters:
  • page (Optional, Default 1)
    • Any valid Page #

http://www.daniweb.com/api/posts/{:ID}/comments http://www.daniweb.com/api/members/{:ID}/comments?page=

Sample Data

Fetch Chat Messages

Parameters Sample Usage
GET Parameters:
  • since_id (Optional)
    • Any Message ID #
  • long_polling (Optional, Default false)
    • true
    • false

http://www.daniweb.com/api/forums/{:ID}/chat
http://www.daniweb.com/api/members/{:ID}/chat

<?php
// Fetch Community Center Chat messages that are newer than Message # 12345
// Pass in an access token to retrieve non-stale data in a live chat environment
// When polling, requests should pass in the since_id retrieved from the previous request
                
// Can be used in a non-live environment or by polling the server at regular intervals
$output = json_decode(file_get_contents(
    'http://www.daniweb.com/api/forums/3/chat?since_id=12345'), true);
var_dump($output);

// Keep the connection open for up to ~30 seconds and "push" new messages to the client
// Instead of polling at regular intervals, you will want to call the server
  // within a while loop that runs until the server sends something back
// The server will end the connection when messages become available or after
  // 30 seconds, whichever comes first, minimizing unproductive http requests
// Ideal for a live environment
$output = json_decode(file_get_contents(
    'http://www.daniweb.com/api/forums/3/chat?long_polling=1&since_id=12345'), true);
var_dump($output);        
?>

Sample Data

Parameters Sample Usage
GET Parameters:
  • query (Required)
    • Any search string
    • Any username
  • page (Optional, Default 1)
    • Any valid Page #

http://www.daniweb.com/api/articles/search
http://www.daniweb.com/api/members/search

<?php
$output = json_decode(file_get_contents(
    'http://www.daniweb.com/api/articles/search?query='.urlencode('round robin algorithm')), true);
var_dump($output);
?>

Requests Requiring Authorization

  • Allows your application to automatically detect which member is using it without the member having to share anything about themselves.
  • Allows your application to automagically gain read / write access to the member profile & personal data of any end user currently using it.
  • Gives end users the ability to authorize your application to access and modify their own profiles on their behalf.
  • Gives your application the ability to access and modify the accounts of end users without the need for them to share their login credentials.
  • Offers the ability to create a Log In with DaniWeb feature to replace or extend your application's own login mechanism.
  • You can generate a client_id and client_secret by registering your application.
  • The client_id and client_secret are hard-coded into the application to authenticate the credentials of the application itself.
  • The credentials of the application's end users are verified and the application's access is explicitely authorized during the OAuth process.
  • The OAuth 2.0 flow for the end user is as follows:
    1. Your application redirects its end users to the DaniWeb authorization page.
    2. If they are not currently logged into DaniWeb, they are prompted to either log in or register. Otherwise, this step is bypassed.
    3. They are prompted to authorize your application to access their accounts before being redirected back to your application.
    4. If they have previously authorized your application, the process is transparent and they are immediately redirected back.
  • From the OAuth process, the application is given an Access Token which can be used to set and retrieve data specific to the end user.

Introduction to OAuth and Serverside tutorial Clientside OAuth tutorial

Who Am I?

Parameters Sample Usage
GET Parameters:
  • access_token (Required)
    • Active Access Token

http://www.daniweb.com/api/me?access_token={ACCESS_TOKEN}

PHP Example:
<?php
// Fetch everything about the current end-user and subsequently decode the response
//    from JSON into a PHP array
$output = json_decode(file_get_contents(
    'http://www.daniweb.com/api/me?&access_token='.$access_token), true);

// Print out the resulting PHP multi-dimensional associative array
echo 'Hi, ' . $output['data']['username'] . '!';
?>
Javascript (jQuery) Example:
<script type="text/javascript">
// Fetch everything about the current end-user and retrive the response as JSONP
// JSONP is a workaround for Javascript's same origin policy
$.getJSON(http://www.daniweb.com/api/me?access_token=' + access_token + '&callback=?',
    function(response) { alert('Hi, ' + response.data.username + '!'); }
);    
</script>

Fetch Articles (additional parameters)

Parameters Sample Usage
GET Parameters:
  • All parameters described above
  • filter (Additional, Optional)
    • recommended
    • viewed
    • watching
  • access_token (Required)
    • Active Access Token
<?php
// This is similar to the version above, but additional filter options are available
//    when passing in an access token

// Fetch C++ articles that I've recently viewed
$output = json_decode(file_get_contents(
    'http://www.daniweb.com/api/forums/8/articles?
    filter=viewed&access_token='.$access_token), true);
var_dump($output);
?>

Fetch Private Messages

Parameters Sample Usage
GET Parameters:
  • access_token (Required)
    • Active Access Token
  • page (Optional, Default 1)
    • Any valid Page #
Required Scope: private_messages

http://www.daniweb.com/api/me/inbox?access_token={ACCESS_TOKEN}
http://www.daniweb.com/api/me/outbox?access_token={ACCESS_TOKEN}

Watch an Article

Parameters Sample Usage
GET or POST Parameters:
  • remove (Optional, Default false)
    • true
    • false
  • access_token (Required)
    • Active Access Token
POST Parameters:
  • id (Required)
    • Any valid Article ID #
Required Scope: watch

http://www.daniweb.com/api/articles/watch
http://www.daniweb.com/api/articles/{:ID}/watch?access_token={ACCESS_TOKEN}

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);

// Stop watching Article # 12345
curl_setopt($ch, CURLOPT_URL, 'http://www.daniweb.com/api/articles/watch');
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'id' => 12345,
    'remove' => true,
    'access_token' => $access_token
));
$output = json_decode(curl_exec($ch), true);
curl_close($ch);
?>

Vote on a Post

Parameters Sample Usage
GET or POST Parameters:
  • vote (Optional, Default 1)
    • 1
    • -1
  • access_token (Required)
    • Active Access Token
POST Parameters:
  • id (Required)
    • Any valid Post ID #
Required Scope: vote

http://www.daniweb.com/api/posts/vote
http://www.daniweb.com/api/posts/{:ID}/vote?access_token={ACCESS_TOKEN}

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);

// Give Post # 12345 a +1 Vote
curl_setopt($ch, CURLOPT_URL, 'http://www.daniweb.com/api/posts/vote');
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'id' => 12345,    
    'vote' => '1',    
    'access_token' => $access_token
));
$output = json_decode(curl_exec($ch), true);
curl_close($ch);
?>

Post Chat Message

Parameters Sample Usage
GET or POST Parameters:
  • access_token (Required)
    • Active Access Token
POST Parameters:
  • room_type (Required)
    • forum
    • member
  • room_id (Required)
    • Any valid Forum / Member ID #
  • message (Required)
    • Chat Message
Required Scope: chat

http://www.daniweb.com/api/chat?access_token={ACCESS_TOKEN}

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);

// Chat in the Community Center chat room (a chat room is defined by a type / id pair)
curl_setopt($ch, CURLOPT_URL, 'http://www.daniweb.com/api/chat');
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'room_type' => 'forum',    
    'room_id' => 3,
    'message' => 'Hello World!',                
    'access_token' => $access_token
));
$output = json_decode(curl_exec($ch), true);
curl_close($ch);
?>