Archive for the 'Mashup' Category

How to display your Break.com videos on your website, simple JS/JSON hack

Saturday, June 14th, 2008

This is a simple and easy tutorial on how to retrieve (in real-time) all your videos from break.com and put them on your website using JavaScript.

In real-time meaning a call to break.com’s WEB API will be made every time you reload the page.

Now, this is not a feature they have exposed to the public yet, but it is there in case you are nerdy enough to figure it out. So this is really a good ol’ innocent hack :)

Read the rest of this entry »

Pull data from Google Search API and decode JSON string using PHP

Wednesday, June 11th, 2008

PHP has a built-in function that can decode a JSON string and turn into an object or an object tree and is called PHP-JSON. This is very helpful for when you need to integrate or mashup with other application such as the google APIs. Here is a quick simple example:

<?php
$json_str = ‘{ “name” : “chris”}’;
$obj = json_decode($json_str);
echo $obj->name;
echo “\n”;

The above will return:

chris

Read the rest of this entry »

Creating a simple Weather.com / GeoIP mashup

Friday, June 6th, 2008

I just finished creating a simple Weather.com and GeoIP mashup.  All you need to do is register with Weather.com and go to their tools / website section.  Then you need to install GeoIP on your server.  Then you need to add the following source code:

$localzone = null;
if(geoip_db_avail(1))
{
 $localzone = geoip_record_by_name($_SERVER['REMOTE_ADDR']);
}
$zip = $localzone['postal_code'];

if(!isset($zip) || $zip ==null)
{
   echo “We could not find your zip code”;
   exit();
}

Mash it up with Weather.com’s source code and that’s it!

 Here is a quick sample

 Here is the source code

What’s an API

Saturday, May 31st, 2008

The term API (Application Programming Interface) is typically used for when referring to a set of methods that are publicly exposed in order to interact/communicate with another application. Let’s say you write a web application that you would like other people to extend and add more features to. In order to do that you create an API…

Here is an example of a very popular “WEB” API: http://apidoc.digg.com/

Digg created a set of public web methods that are accessible via HTTP (hence why I call them “web” methods) and that allowed me to create my own little app on my server that displays Digg data. Now all APIs are different and their is no standard naming convention that I know of.

Google has them as well http://code.google.com/. When you integrate with external API you call that a mashup. I created my own Google maps mashup and you can see it here

Here is another more in-depth example:

Let’s say you have a contacts database and you would like to expose that via an API. Here are the steps you would need to take. Assuming that you are not a programmer I’m going to keep this light.

  1. Write a new page using your programming language (Perl, C#, PHP, Python, Rubi, etc) that talks to your contacts database and call it api.php (Will use PHP for this example)
  2. Create a method inside your page that will return contact info and call it GetContacInfoByName(string name).
  3. Write the necessary code to take a parameter and call that function, so let’s say if I wanted to invoke the GetContactInfoByName method I need to use <domain>/api.php?invoke=GetContactInfoByName&name=Chris This URL contains two parameters “invoke” and “name”. Invoke is used for selecting the method you wish to trigger and name is used for retrieving the data.

I wrote a page on my wiki and created a some code examples for the client/API and the response. Client being the API.

Setting up MaxMind GeoIP Lib to work with Google Maps

Saturday, May 24th, 2008

Google maps has a pretty extensive open API that gives users the ability to create really fancy maps for their websites.  The way you comunicate with the google API is via their own JavaScript Libraries. 

The first thing you need to do is get a developer key
http://code.google.com/apis/maps/signup.html

Then you need you drop the sample HTML on your website and veriy that it works. Like I did here:
http://www.chrisdevbox.com/lab/googlmap/

Then you need to install MaxMind C API library and download their database.  You also need to install the PHP client libraries and recompile PHP.  I added instructions on how to do that here:
http://wiki.chrisdevbox.com/index.php/Setting_up_GeoIP_by_MaxMind

Here is the final example:
http://www.chrisdevbox.com/lab/googlmap/google-map-by-ip.php

Here is the PHP section, as you can see after installing the client API you don’t have to do a lot of coding to maket it work…

$localzone = null;
if(geoip_db_avail(1))
{
 $localzone = geoip_record_by_name($_SERVER['REMOTE_ADDR']);
}