Fetch Your Feed Subscriber Count with The FeedPress API

When I created FeedPress, I always wanted to make the analytics open and easily accessible. That’s why the API has been made available since day one and we are constantly working on improving it.

Today, I’m going to show you how you can easily fetch your feed subscriber count. Hopefully it will give you some ideas about implementing the FeedPress API into your scripts.

1. Create an app

Creating an API app on FeedPress is quite easy. Just fill out the New app form:

New app

You will instantly get a new API key for your app.

2. Generate a token

Even if there are API methods to generate a token through the API, since we will only use this app with our own account, we just have to click on the handy “Generate token” link on the app’s page:

Generate token

Awesome! A token has been created for you.

The precious token

We have an API key and a user token; let’s make our first request to the API.

3. Make the HTTP request

The FeedPress API is simple and thus makes things easy when it comes to integrating it into your apps. For this example, I want to retrieve how many RSS subscribers I have. I will use the /feeds/subscribers.json method with the following parameters:

  • key: My API key
  • token: My user token
  • feed: The name of my feed

Let’s make our API request via command line, using curl:

curl "http://api.feedpress.it/feeds/subscribers.json?key=5385da3b7df3d&token=5385da5264278&feed=maxime"

I’m now getting a JSON object containing the subscribers statistics for the last 30 days. It works!

{
    "stats": [
        {
            "day": 1364425200,
            "greader": 742,
            "other": 13,
            "direct": 186,
            "newsletter": 21
        },
        ...
    ],
    "code": 1
}

4. Using it in my PHP script

Now, I’d like to have the current subscribers count. I’ll use PHP and HttpRequest to get the job done.

<?php

$r = new HttpRequest('http://api.feedpress.it/feeds/subscribers.json', HttpRequest::METH_GET);
$r->addQueryData([
    'key' => '5385da3b7df3d',
    'token' => '5385da5264278',
    'feed' => 'maxime',
]);

try {
    $r->send();
    if ($r->getResponseCode() == 200) {
        $json = json_decode($r->getResponseBody(), true);
        echo 'I have ' . $json['stats'][0]['greader'] . ' readers on /maxime.';
    }
} catch (HttpException $e) {
    echo 'Error: ' . $e->getMessage();
}

As I expected, I get the following result:

I have 742 readers on /maxime.

In only a few minutes, I managed to get the current subscriber count of my feed hosted on FeedPress. This live example is not production-ready — you would want to add some cache to avoid hammering our servers (seriously, please don’t hammer our servers).

There is a lot of data available through the API. In fact, if you see something you’d like to get through the API, please let us know and we’ll try to accommodate.

The API is available to Premium members. It’s the best way to support our work and make FeedPress a sustainable service.

Are you a developer? We want you!

If you are a developer who wants to use the FeedPress API in a public project, we would be happy to give you a Premium membership for free and promote your project as much as we can. Feel free to contact us.

Leave a Reply