Getting Started

ianjennings edited this page Apr 9, 2011 · 5 revisions

HackNY Hackathon Starter Script

This script is intended to give new programmers (hackathon or else) something to start hacking on quick. I’m assuming that you’ve already got a PHP environment set up somewhere. If not, check out XAMPP.

This file just makes a simple api request and displays the response. The API for this example is, an API for turning normal links (http://…) into embeddable widgets (video players, slideshows, etc).

Copy and paste it into a file called index.php in the directory /htdocs (if using XAMPP).

Follow the XAMPP instructions to connect to your server and you should see a webpage with a video, title, and description. Take this example, and do it a couple more times. Mash up APIs with one another and make something cool!

Read the full uncensored story at

// HackNY Hackathon Starter Script
// By Ian Jennings

// the url parameter for the api
$my_url = "";

// construct an api call using $my_url.
// to combine two strings in php (concatenation) you use a period
$api_url = "" . $my_url;

// download the contents of the api_url.
$api_downloaded_file = file_get_contents($api_url);

// gave us data in a format called json
// we're going to convert the data from json to a php object using one simple function
$response_object = json_decode($api_downloaded_file);

// the response is now an object, var_dump will show all the properties of that object
// uncomment the next line to see everything we got back from the api request
// var_dump($response_object);

// we can do things now like display the video title, description, and embed
// check out lines 28, 31, 32, 34
        <!-- We can jump in and out of PHP, to create a dynamic HTML page. -->
        <title>That Video: <?php echo $response_object->title; ?></title>
        <h1><?php echo $response_object->title; ?></h1>
        <p><?php echo $response_object->description; ?></p>
        <div class="html">
            <?php echo $response_object->html; ?>