넷로그로 가기

초 남음

Developer / Documentation / PHP applications

This article describes working with the custom Netlog REST API which is deprecated.

Instead, please use our OpenSocial implementation instead, using our OpenSocial REST API directly or, for example this OpenSocial PHP client which takes care of the authentication for you.

If you'd still like to use this API, please get in touch first.

Introduction

This tutorial describes how you can create your own application. We will make a simple demo application called demoApplication that you can use as a template for creating your own applications.
The demoApplication is written in PHP5 and uses this client library.

This tutorial will first give a short overview of some important concepts before going into detail about how to make an application.

Application ID and Application Key

In order to identify the different applications, you need to acquire an Application ID and Application Key. The first one is for identifying your application while the latter one is used for securing your API calls (see further) and should be kept strictly private.
For the moment, these ID's and Key's can only be acquired through Netlog.

Callback URL

An application is a sort of micro-site you set up on your own server. The callback URL is typically the URL to the directory where you will set up this micro-site.
The callback URL is our entry point for your application and is e.g. used for the authentication and rendering of your application.

Building your application

Start by downloading the php5 client library.
This library consists of three classes: Netlog, NetlogClient and NetlogException. The first one contains functions to call all API methods that are currently available. NetlogClient is a class that handles the calling of the API server and returning the result. When an error occurs during the call of an API method, a NetlogException is thrown which you can use for your own error handling.

When creating your application, you start by creating an app.inc.php file that you will include at the top of all your php files in your application. Paste the following code in your file:

<?php
require_once ("class.netlog.php");
//TODO: Fill in your own Application ID and Application Key
$appID = "YourAppID";
$appKey = "YourAppKey";
$netlog = new Netlog($appID, $appKey);
$netlog->require_login();
//Authenticate your application
try
{
 $netlog->auth_authApp();
}
catch(NetlogException $e)
{
 //Your own Exception handling here
}
?>

Now you can start building all the different files that make up your application. Start with an index.php file which will be the home page of your application. For example, you can use this code:

<?php
require_once ("app.inc.php");
echo "Hello World!";
//You can do different API calls from now on. Let's print out all the photo's of the current user:
try
{
 $photos = $netlog->photos_get("src_small,caption,link", $netlog->users_getLoggedInUser());
}
catch(NetlogException $e)
{
}
echo "<h1>Your pictures</h1>";
foreach($photos AS $photo)
{
 echo '<a href="'.$photo['link'].'"><img src="'.$photo['src_small'].'" alt="'.$photo['caption'].'" title="'.$photo['caption'].'" /></a>';
}
?>