---
title: 'Klout Library for CodeIgniter'
url: 'https://www.patrickpopowicz.com/blog/klout-library-for-codeigniter'
markdown: 'https://www.patrickpopowicz.com/blog/klout-library-for-codeigniter.md'
date: '2011-12-04'
description: 'Last week, I talked about how and why I use Klout as a useful metric. In that post I mentioned that I would be working on a library to use the Klout API with CodeIgniter. Incidentally, my Klout score has dropped a point since then! When I finally got to writing it up on Friday afternoon I managed t…'
taxonomy:
  tag:
    - codeigniter
    - php
    - klout
    - technology
    - 'social media'
  category:
    - blog
  archives_month:
    - dec_2011
  archives_year:
    - '2011'
---

# Klout Library for CodeIgniter

- [ Blog ](https://www.patrickpopowicz.com/)
- [ About ](https://www.patrickpopowicz.com/about)

 [ ![Gravatar](https://www.gravatar.com/avatar/c949590db430ad4f00a8013b56af43db?s=90) ](https://www.patrickpopowicz.com "patrick popowicz dot com")#  [patrick popowicz dot com](https://www.patrickpopowicz.com) 

 ![](https://www.patrickpopowicz.com/images/5/5/5/c/d/555cdb87db23dab1cf5dc523f20ade8a61620589-klout-io.png) 

## [Klout Library for CodeIgniter](https://www.patrickpopowicz.com/blog/klout-library-for-codeigniter)

 Sun, 04 Dec 2011 10:08:00  /   Patrick Popowicz   /  [codeigniter, ](https://www.patrickpopowicz.com/tag:codeigniter) [php, ](https://www.patrickpopowicz.com/tag:php) [klout, ](https://www.patrickpopowicz.com/tag:klout) [technology, ](https://www.patrickpopowicz.com/tag:technology) [social media](https://www.patrickpopowicz.com/tag:social%20media) 

Last week, I talked about [how and why I use Klout](http://patrickpopowicz.com/2011/11/how-and-why-i-use-klout/ "How and why I use Klout") as a useful metric. In that post I mentioned that I would be working on a library to use the Klout API with CodeIgniter. Incidentally, my Klout score has dropped a point since then!

When I finally got to writing it up on Friday afternoon I managed to erase all of my work with a poor git decision (still kind of new to git) and had to recode from scratch. In doing so, I pared the library down by using the PHP magic method [\_\_call()](http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods "php.net Magic Methods") since the API’s interface is extremely simple and generic.

The API uses either GET or POST, but it is read-only in either case. POST is only used when you are looking for data for more than one user. In my testing, I found that the API will return all the requested information regardless of how you send it over and with how many users, even though the API’s documentation says that multiple user requests need POST.

Using the Klout library is simple, but first you need to [register a Mashable account and your application with Klout](http://developer.klout.com/member/register "Klout Developer Registration") and add the [API key from your account](http://developer.klout.com/apps/mykeys "Klout Developer Account") to the config file. All you need to do is load the library and then you can run your code.

![](https://www.patrickpopowicz.com/user/pages/01.blog/klout-library-for-codeigniter/Klout-Registration.png)Register an account and your application with Klout.

As I said before, the API is pretty simple. There are five endpoints as of Version 8: Klout score, Show user, Topics, Influenced by and Influencer of. All of those endpoints support either JSON or XML as a return format (library default is JSON). You can read the README file and if you need more information on the API itself, go read [Klout’s API documentation](http://developer.klout.com/docs "Klout's API documentation").

They also have an [excellent interactive demo](http://developer.klout.com/iodocs "Klout Interactive Demo") that you can use once you have your API key. The demo allows you to use any of the endpoints with your API in the browser and you are able to pass through whatever users or format you want and it will show you the response headers, body and the target URL that was generated.

![](https://www.patrickpopowicz.com/images/1/4/b/d/1/14bd12671e3e44086fae7f05ea40ad9a586bf3ea-klout-io.png)Klout IO Docs

## Example Code:

This library returns the response from the API directly and doesn’t do any JSON decoding or XML work for any of the standard endpoints. The only exception to this is the convenience profile method that I’ve added, which returns a stdClass object that compiles all the five endpoints for a single user.

You can get the library [from the repo](https://www.patrickpopowicz.com/blog/klout-library-for-codeigniter/git@github.com:patrickpopowicz/codeigniter-klout.git "Klout Library for CodeIgnter repo at github.com") or [download the latest version](https://github.com/patrickpopowicz/codeigniter-klout/zipball/master "Download latest version of Klout Library for CodeIgniter by Patrick Popowicz at github.com") directly.

This Klout library is built for use in [CodeIgniter](http://www.codeigniter.com "CodeIgniter") (compatible with at least version 1.7 forward), but it can also be used for non-CodeIgniter applications, you’d just need to remove the references to CodeIgniter (the “\_ci” instance reference and log\_message() usage in the constructor, and the “defined(‘BASEPATH’)” reference at the top) and keep the settings either in a separately loaded config file or at the top of the library’s class declaration. Then, instead of using the CI loader, you would simply ‘include’ the library’s class.

 [ Newer Post](https://www.patrickpopowicz.com/blog/bit-ly-spark-for-codeigniter) [Older Post ](https://www.patrickpopowicz.com/blog/how-and-why-i-use-klout)

### Recent Posts

- [Klout Spark for CodeIgniter](https://www.patrickpopowicz.com/blog/klout-spark-for-codeigniter)
- [bit.ly Spark for CodeIgniter](https://www.patrickpopowicz.com/blog/bit-ly-spark-for-codeigniter)
- [Klout Library for CodeIgniter](https://www.patrickpopowicz.com/blog/klout-library-for-codeigniter)
- [How and why I use Klout](https://www.patrickpopowicz.com/blog/how-and-why-i-use-klout)
- [bit.ly Library for CodeIgniter](https://www.patrickpopowicz.com/blog/bit-ly-library-for-codeigniter)

### Categories

- [Codeigniter](https://www.patrickpopowicz.com/tag:codeigniter)
- [Php](https://www.patrickpopowicz.com/tag:php)
- [Klout](https://www.patrickpopowicz.com/tag:klout)
- [Bitly](https://www.patrickpopowicz.com/tag:bitly)
- [Technology](https://www.patrickpopowicz.com/tag:technology)
- [Social media](https://www.patrickpopowicz.com/tag:social%20media)

### Calendar

 <span>Copyright © 2016 Patrick Popowicz</span>

 <span>Theme by <a href="http://www.andersnoren.se">Anders Noren</a> — </span><a title="To the top" class="tothetop">Up ↑</a>

---

## Navigation

- Parent: [Blog](https://www.patrickpopowicz.com/index.md)
- Previous: [bit.ly Spark for CodeIgniter](https://www.patrickpopowicz.com/blog/bit-ly-spark-for-codeigniter.md)
- Next: [How and why I use Klout](https://www.patrickpopowicz.com/blog/how-and-why-i-use-klout.md)
