User Information via Loklak API

While working on “adding loklak API support to  wordpress plugins”, I found that a lot plugins require Twitter user information e.g. profile_pic, followers_count, tweets by the user etc.

One can get an exhaustive user information using Loklak search and user APIs. In this blog post I would show how one can combine the results from Loklak’s Search and User API to provide all kinds of data required by a WordPress plugin (e.g.).

Starting with Search API!


in url would give you results like this:


As you can see, it provides all tweet (tweeted by the <user>) related information and a small user profile like this:


But what if you require his location, followers_count, friends_count, no. of tweets he has posted till now etc, you would have to take help from the Loklak User API. Sample results for

are given below:


But somehow you also require the information of his followers and people he is following. How do you achieve that? Well Loklak API has provision for that as well. All you need to do is add followers=<count> or following=<count> as need be.

Following data would be added to your user.json results.


It would give you the user information of twitter users followed by that user. Recursively you can get their tweet data, their followers and on and on!!

In order to get complete user profile, you can merge the results from Search and User API and create wonderful applications.

To do all this using Loklak PHP API, refer to the code snippet below.

$connection = new Loklak();
$tweets = $connection->search('', null, null, $username, $no_of_tweets);

$tweets = json_decode($tweets, true);
$tweets = json_decode($tweets['body'], true);

$user = $connection->user($username);
$user = json_decode($user, true);
$user = json_decode($user['body'], true);

$tweet_content = $tweets['statuses'];
for ($i=0; $i < sizeof($tweet_content); $i++) {
     $tweet_content[$i] = array_merge($tweet_content[$i], $user);
User Information via Loklak API

Coveralls and Travis support for Loklak APIs

Today I will be talking about Coveralls and Travis integration into Loklak APIs.

Travis CI

Wikipedia defines it as:

Travis CI is a hosted, distributed continuous integration service used to build and test software projects hosted at GitHub.

Travis takes care of the tests and deployment of apps. Travis integration is really easy when you have your tests ready. It was a basic three step process:

  1. Registering the API repos with Travis.
  2. Adding .travis.yml to the API github repository. e.g. For loklak_php_api , the file looks like this.
    language and php versions are specified for which the API is to be tested.  We added phpunit Tests in script since we wanted Travis to execute the tests.
  3. Trigger the first build with a git push

And the first build is up.



Coveralls is a presentation of the coverage of test suite you pass to Travis to build. In layman language, Coveralls helps you find the lines in your code which were not tested by your Test Suite.

Coveralls integration is also simple, but might involve some googling if you are working on PHP. I will take the example of loklak_php_api here.

  1. Registering the API repo with Coveralls.
  2. Modifying the .travis.yml to this
  3. Creating a .coveralls.yml file to specify the paths required to send the coverage to Coveralls
  4. Since testing of only loklak.php was required, so a phpunit.xml file was added to exclude Tests and Requests directories from test suite.

After configuring the environment, there we have it. Coveralls result showing the code coverage of our test suite on loklak.php!

Coveralls and Travis support for Loklak APIs

Creating a Loklak App!

Hello everyone!

Today I will be shifting from course a bit. I will talk about how you can use Loklak API, create an app and show it off by deploying it on .

Lets dive in!


This is how the loklak apps page looks like. If you want your creation to end up here, follow some simple steps.

Firstly clone loklak_server github repo.

git clone

Deploy loklak server on localhost and you’ve got your “dev env” ready!

The next thing you need is an idea for an app which will use loklak API. When you have it, create a subdirectory under your loklak_server/html/apps/ folder and name your app. Now you start coding!! For easy quick-start, you can look at the boilerplate.

If you are planning to add some styles and scripts to your app, these must either be already present in loklak or you might have to add them explicitly. e.g. look at this app and notice the css and js folders which contain the custom scripts being used in the app.


index.html is the landing page for your app. The app.json file you create must have an json-Id format. You can use the json-Id file from an existing app for reference.

When you are sure about which Loklak API functions you want to use in your app, modify the "permissions" field in app.json to a comma-separated list of all api paths, that the app calls. This is used to apply authorization markers to the app, so it becomes visible if the app is actually usable for the user. e.g. look at this. Since this app just uses the search API to get the tweet feed. The permissions a user requires to use this app is    "/api/search.json" .


Once you are done with coding your app, test it thoroughly on your local installation. See if your app appears under http://localhost:9000/api/apps.json in the app list. Test that your app is not browser specific and make sure to add a backlink to /apps/ to make it easier for user to browse to other apps from yours.

Since now you are sure that your app is “Loklak ready” all you have to do is send a pull request to Make sure that all your files are contained into one commit.

When your app gets merged, you would be able to see it here.

Thats all folks. For more info refer to the full documentation here.
Happy Coding!!!

Creating a Loklak App!

Loklak enters WordPress Universe

In my last post, I briefly commented on how one could now use Loklak API in WordPress plugins. Lets discuss that here in detail.

The post is mostly focused on novice WP plugin/widget developers. If you ain’t novice (or don’t consider yourself to be) just a quick skim would be enough.

Suppose, you want to make a plugin with functionalities as given below:

  1. View tweets by a twitter account
  2. Between a time frame
  3. Containing specific “mentions” and “hashtags”

After deciding the design, you want best tools at your disposal. You search for the twitter API and find that you need to make a twitter app to use the API in your plugin.

Now you ask yourself “Is there a better way?”.

Yes there is! Its called Loklak!

You can use Loklak’s PHP API (refer to my previous blog post) and the included WordPress library to render tweets anonymously (No annoying ‘Create an app’ procedures!).

“Oh yes! that’s what I was looking for. How do I use it?”

So lets dive in!

When you are done with your plugin’s frontend, add loklak_php_api as a submodule (if using Github) or just download the zipped file and extract it in your plugin repo.

To add loklak PHP API as a submodule to your project, just execute the below-mentioned command.

cd path/to/your/project;
git submodule add; 

Include loklak.php in your plugin file where you want to render your Loklak API results.


Create an object of Loklak class.

$loklak = new Loklak($base_url);

Since we want our tweets filtered based on points we listed above, we could use the search API.

See the definition below.


You just need to create a form to input the arguments and you will be good to go!

For example: If the plugin user wants to see tweets by @lklknt which mention #loklak and were tweeted between 31st January, 2015 and 31st December, 2015.

$query = '#loklak';
$since = '2015-01-31';
$until = '2015-12-31';
$from_user = `lklknt';

Considering that we got these values from the frontend form where user could enter his choices. This is how the search function would look like.

$tweet_results = $loklak->search($query, $since, $until, $from_user);


You can use these results directly in your plugin.

For plugin developers who are currently using twitter API and want to provide Loklak as an option to their users.

Just include Lib/loklak-api-admin.php in your settings page to display loklak as an option.

Loklak enters WordPress Universe

Loklak API now supports PHP

Now loklak API comes in PHP language as well. It provides a simplistic interface for all your PHP applications.

Selection_010Being released as a package, it uses Requests API to render results from and all you really need to do is include loklak.php in the file where you want loklak API results.


Create an object of class Loklak

$loklak = new Loklak($base_url);

and you are good to go!

The Aggregations API has been improved to send the count parameter with request query. Error Handling has been enabled for better debugging!

Aggregations API

It also comes with exhaustive list of examples for each API function, to help your application take full benefit of the services Loklak provides.


Loklak Aggregations API example

Tests are written with PHPUnit to make it robust! and PHPLint is used to keep it clean!

Now you can even add loklak API support to your WordPress plugins via admin settings module in /Lib/loklak-api-admin.php.

Just include it in your file as need be.



Just tick the checkbox and unleash the power of Loklak!

Loklak API now supports PHP

The all new “Gooey” GUI for Python API

Loklak Python API is now Windows friendly with the all new GUI.


Thanx to Gooey!  You don’t need to be command prompt or Powershell “specialist” to use the Loklak Python API. Just use the GUI and follow simple steps to fetch results from the powerful Loklak. Gooey provides several UI options for python applications.


After a bit of thought and careful examination of GooeyExamples, it became pretty conclusive that the “Column Layout” would be perfect to capture the detailed options that Loklak API supports.

Earlier code structure of   /bin/loklak did not support the “Column Layout” UI format. UI demanded the use of subparsers(refer this and this) and therefore some tweaking was required. This is how the code transformation looks like!

This slideshow requires JavaScript.

And the best part is that power users can still enjoy the terminal!


After the API was “Column UI” ready, only two lines are required to integrate Gooey with the API.

from gooey import Gooey

before def main(): in /bin/loklak

And there you go. These are how the results look like!



Pretty sleek isn’t it!

To download and install Gooey please refer this.

The all new “Gooey” GUI for Python API