Tag Archive | "api"

Tags: ,

Reddit’s Secret API

Posted on 24 November 2008 by Ryan

Over the past few weeks I have been working on creating a tool to gather some social media metrics to track social media optimization campaigns. Friendfeed is your friend if you’re embarking on the same project. While looking for a native reddit API however I stumbled across a post on code.reddit.com that mentioned an API endpoint.

http://code.reddit.com/ticket/154:

In many applications, such as Socialite, it is valuable to look up information about a link on reddit. Currently, there are two good ways to do this using the JSON API:

Info call
Example: http://www.reddit.com/api/info.json?count=1&url=STORYURL

The API “info” call is an ideal way to look up reddit stories by URL. However, in some cases, looking up stories by URL alone presents problems:

1. URLs are not mapped to stories on a one-to-one basis. Since the same URL can be posted to many subreddits, when looking up stories by URL, it becomes necessary to constrain the search by subreddit, e.g.: http://www.reddit.com/r/subreddit/api/info.json?count=1&url=STORYURL

For a typical reddit story the json looks like:

{"kind": "Listing", "data": {"children": [{"kind": "t3", "data": {"subreddit_id": "t5_6", "clicked": false, "name": "t3_70ehq", "ups": 3709, "created": 1220933746.0, "url": "http:\/\/voices.washingtonpost.com\/the-trail\/2008\/09\/08\/obama_to_palin_dont_mock_the_c.html", "num_comments": 871, "downs": 943, "author": "neoabraxas", "domain": "voices.washingtonpost.com", "subreddit": "reddit.com", "score": 2766, "likes": null, "title": "Obama to Palin:\"Don't mock the Constitution. Don't make fun of it. Don't suggest that it's not American to abide by what the founding fathers set up. It's worked pretty well for over 200 years.\"", "hidden": false, "saved": false, "id": "70ehq"}}, {"kind": "t3", "data": {"subreddit_id": "t5_2cneq", "clicked": false, "name": "t3_70e4r", "ups": 96, "created": 1220928368.0, "url": "http:\/\/voices.washingtonpost.com\/the-trail\/2008\/09\/08\/obama_to_palin_dont_mock_the_c.html", "num_comments": 9, "downs": 61, "author": "andybigs", "domain": "voices.washingtonpost.com", "subreddit": "politics", "score": 35, "likes": null, "title": "Obama to Palin: 'Don't Mock the Constitution'", "hidden": false, "saved": false, "id": "70e4r"}}]}}

So there you have it. No auth string required, just open access to a portion of reddit’s db. So far the only endpoint visible is URL. With a little trial and error you can probably find some other useful endpoints other then the URL one listed.

Comments (4)

Tags: , ,

Using the Digg API

Posted on 06 April 2008 by Ryan

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.

<form action="" method="post">
<table border="0">
  <thead>
    <tr>
      <td colspan="2">User Lookup</td>
    </tr>
  </thead>
<tbody>
  <tr>
    <td>User Name</td>
    <td>
  <input maxlength="50" name="uid" size="25" type="text" /></td>
  </tr>
  <tr>
    <td></td>
    <td><input name="submit" type="submit" value="submit" /></td>
  </tr>
</tbody>
</table>
</form>

Code

The backend 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 "<div id=\"archivebox\">";
                echo "<h2><img src="\" alt="" />";
                echo "$name";
                echo "User Since: ";
                timestamp_to_date ($registered);
                echo "";
                echo "Profile Views: $profileviews ";
                echo "</h2><h3>User Links</h3>";
                echo "<ul>";
                }
                foreach($user->links as $link) {
                $href = $link->href;
                $description = $link->description;
                echo "<li><a href="$href">$description</a></li>";
                }
                echo "</ul>";
                echo "</div>";

        } 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 "<div id=\"archivebox\">";
                echo "<h2><img src="\" alt="" />";
                echo "$name";

                echo "User Since: ";
                timestamp_to_date ($registered);
                echo "";
                echo "Profile Views: $profileviews ";
                echo "</h2><h3>User Links</h3>";
                echo "<ul>";
                }
                foreach($user->links as $link) {
                $href = $link->href;
                $description = $link->description;
                echo "<li><a href="$href">$description</a></li>";
                }
                echo "</ul>";
                echo "</div>";
		}
?>

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

Comments (0)

Tags: , ,

New Keyword Rankings Tool

Posted on 20 March 2008 by Ryan

We’re beta testing a new keyword rankings tool that pulls data from the Seodigger.com api. It’s basically one api call to seodigger specifying the domain to search for and a variable that limits results. We then wrap it up in some pretty css via jquery. Please check it out and report any bugs to ryanunderdown >at< gmail >dot< com

Comments (1)

Blog Advertising - Advertise on blogs with SponsoredReviews.com Advertise Here