digg, featured

Using the Digg API06 Apr

Digg’s new API is impressive. Incorporating your digg user account activity or your domain’s popular posts into your blog or using it as part of a micro blogging strategy is a snap. The easiest way I have found is to use Nick Halstead’s Simple Digg API Usage script. This script doesn’t require PEAR and it works on PHP 4 & 5.

Digg User Lookup

The Basics

To get started, you need to create (as in ‘out of thin air’) an application key and a user agent. There is no application key signup like Google or Youtube, however the application key you choose should meet the following requirements:

from the digg api wiki
The value of the appkey argument must be a valid absolute URI (see IETF RFC 2396) that identifies the application making the request. The URI might point to:

  • The application itself, if it’s a web application.
  • A web page describing the application.
  • A web page offering the application for download.
  • The author’s web site.

Html

The html for the form to display to request digg user name.

User Lookup
User Name

Code

The backed code to function the submit request

decode($response);
        foreach($decoded->users as &$user) {
             // $user = $decoded->users;
                $name = $user->name;
                $icon = $user->icon;
                $registered = $user->registered;
                $profileviews = $user->profileviews;
                              function timestamp_to_date ($registered)
                              {
                              $date = date ('m-d-Y' , $registered);
                              echo $date;
                              }
                echo "
"; echo "

"; echo "$name "; echo "User Since: "; timestamp_to_date ($registered); echo ""; echo "Profile Views: $profileviews "; echo "

User Links

"; echo "
    "; } foreach($user->links as $link) { $href = $link->href; $description = $link->description; echo "
  • $description
  • "; } echo "
"; echo "
"; } else { //form hasn't been submitted $user = "elebrio"; require("JSON.php"); ini_set('user_agent', 'ic/1.0'); $appkey = 'http://indexedcontent.com'; $response = file_get_contents("http://services.digg.com/user/$user?appkey=$appkey&type=json"); $json = new Services_JSON(); $decoded = $json->decode($response); foreach($decoded->users as &$user) { // $user = $decoded->users; $name = $user->name; $icon = $user->icon; $registered = $user->registered; $profileviews = $user->profileviews; function timestamp_to_date ($registered) { $date = date ('m-d-Y' , $registered); echo $date; } echo "
"; echo "

"; echo "$name "; echo "User Since: "; timestamp_to_date ($registered); echo ""; echo "Profile Views: $profileviews "; echo "

User Links

"; echo "
    "; } foreach($user->links as $link) { $href = $link->href; $description = $link->description; echo "
  • $description
  • "; } echo "
"; echo "
"; } ?>

In order to get this code working on your site, you will need to change two variables.

  • appkey - replace with your domain
     $appkey = ‘http://indexedcontent.com’;
  • user agent
     ini_set('user_agent', 'ic/1.0');

    ic/1.0 is my site’s current user agent. You can basically name this whatever you want.

Additional Resources

Leave a Reply

About

Indexed Content is an up and coming SEO & brand management firm based out of Mesa, Arizona. We specialize in link building, copywriting, and highly successful submissions to most major social media outlets. For more information please call (602) 652-2615 or email info@indexedcontent.com.

Contact

Phone: 602-652-2615
Email: info@indexedcontent.com
Mail: 1853 N Oracle Mesa, AZ 85203