Install custom social share counters on your website with your own hosted solution, which only makes a single API request and loads minimal or zero assets to display the counters.
Check out meddelare.com!
View examples on meddelare.com/meddelare-examples.
Share count fetcher
Node.js promise-based, asynchronous, parallel, per-URL social network share count fetcher -- the base of Meddelare.
Features
- Get counts from multiple social networks in a single API call, returned as a javascript object literal.
- Retrieval is asynchronous and uses bluebird promises.
- The library calls social networks in parallel, making it (approximately) as fast to get the count from one as several at once.
- Super-fast in-memory cache keeps the most recent results per network and url.
Getting started
Install package in your project folder
npm install --save meddelare-counters
Fetch counts from social networks
var SocialButtonsCounts = require("meddelare-counters"),
socialButtonsCounts = new SocialButtonsCounts();
var url = "http://meddelare.com",
networks = [
"facebook",
"twitter",
"googleplus",
];
socialButtonsCounts.retrieveCounts(url, networks)
.then(function(results) {
console.log("Success!", results);
})
.catch(function(err) {
console.error("Fail!", err);
});
Url
Use the url
parameter to specify the address which you want to retrieve the number of shares for, for example http://meddelare.com
or a more specific url poiting to a specific page.
Networks
Currently Twitter, Facebook and Google Plus are supported.
Use the networks
parameter to specify which ones you want to use, as an array of strings, for example ["facebook", "twitter", "googleplus"]
or ["facebook"]
.
Returns
The function returns a Promise. It resolves using .then(function(result){ ... })
for most cases, only rejecting using .catch(function(err){ ... })
when something exceptional happens -- but please expect and implement both.
If a request to a social network failed, a count of -1
is returned for that network.
{
"facebook": 5281,
"googleplus": 42,
"twitter": 8719
}
Configuration
Configure the middleware instance at creation time, for example new SocialButtonsCounts({ unknownCount: 0 })
.
These are the default values.
{
logger: console,
memoryCache: {
goodResultTimeout: 4 * 60 * 1000,
badResultTimeout: 1 * 60 * 1000,
timeoutResultTimeout: 10 * 1000,
},
unknownCount: -1,
}
Thanks
Many thanks goes out to Taskforce for their social-buttons-server (released into the Public Domain) -- especially the creator @thomasdavis and contributor @beaugunderson. This software, meddelare-node-counters, is based on their work.
Copyright (c) 2015 Team Meddelare http://meddelare.com/ All rights reserved.
When using meddelare-node-counters, comply to the MIT license.