I’m developing a plugin to display stats for downloads and various other information that developers might want to display on their sites about what they have developed.
I’ve found documentation on some of what I need and dug up some other undocumented resources I can use, but the one thing I still haven’t been able to dig up is where I can retrieve the downloads today information that is shown on a plugin’s stats page.
All the other stats in the history table could be parsed from the URL below, but that link provides no information on a day that is currently in progress: http://api.wordpress.org/stats/plugin/1.0/downloads.php?slug=[plugin-slug]
For those curious, the other APIs already being used are:
http://api.wordpress.org/stats/plugin/1.0/[plugin-slug]
(plugin versions in use)
and
http://api.wordpress.org/stats/plugin/1.0/
(POST requests return a bunch of data about plugin)
I know there are some solutions out there that involve just scraping the HTML page for the data needed, but unless there really is no other option (which seems unlikely) I don’t wish to take that approach.
As a side note, the documentation in the Codex for the WP.org API is almost non-existent. It would be amazing if someone with some knowledge of the system could fill it out some! A lot of how it works doesn’t seem intuitive to me.
NOTE: This was previously posted on the wp.org forum for a week with zero responses so I thought I would try for a better result over here.
Late answer
A mini plugin as local API
This plugin gives you – after you filled in the slug of your repository – the downloads stats as array. The keys are the dates, the values the downloads.
Usage
To get only the last day + the download number:
The
/stats/plugin/1.0/downloads.php
endpoint returns a JSON list the number of downloads for each day:Replace
{slug}
with your plugin slug.The
&limit=1
parameter sets how many days back you want to go. The last day is presumably “today”.The
&callback=someJsFunction
part is optional.Also note that in order to get the total number of downloads in a nice JSON format you can use:
Here is one idea:
You always have the possibility to scrape the plugin’s download html page:
while you don’t have any json/xml/rss sources with the today’s download counter.
The html part you are interested in has this form:
You could use wp_remote_get() and cache the results.
Here is a function to fetch the data, it takes a plugin_slug (like akismet) as input:
You can use it like this:
and it will give you results like:
ps: just remember that the html of the page can change in the future 😉
The API does not seem to provide this info. The two datasets you can grab for plugins are:
http://api.wordpress.org/plugins/info/1.0/[plugin name]
This will return total downloads, not per day.
http://api.wordpress.org/stats/plugin/1.0/[plugin name]
This will return the versions
You will have to scrape the HTML.