Socket
Socket
Sign inDemoInstall

socoapi

Package Overview
Dependencies
28
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    socoapi

JSON API for social media widget share counts.


Version published
Weekly downloads
1
Maintainers
1
Created
Weekly downloads
 

Readme

Source

socoapi

Want to create a custom look for social media buttons from Facebook, Pinterest and Google? Are you tired of the vendor supplied widget styles when you use their embed scripts?

socoapi is a JSON API for obtaining share counts of your website on social media sites like Facebook, Pinterest, and Google+. Install socoapi on your server so your website can use custom styles for share buttons hosted on your pages.

Installation

npm install socoapi

Usage

Start the socoapi server before you use the API.

socoapi provides one method: listen(port, cachettl [, callback]).

All parameters are required except for callback. Passing a value of false for cachettl will force socoapi to not use caching and each request will get the counts from the vendor's server. Cached values are removed after cachettl milleseconds and refreshed on the next request.

Supplying a cachettl is recommended to not overburden any vendor server needlessly.

// Standalone
var socoapi = require('socoapi');

socoapi.listen('3535', 3600000, function(port, ttl) {
  console.log('socoapi now listening on port ' + port + ' with cache ttl of ' + ttl + ' ms');
});

// Embedded
var app     = require('express')()
  , socoapi = require('socoapi')
;

// If using a reverse proxy
app.enable('trust proxy');

app.listen('3000', function() {
  socoapi.listen('3535', 3600000, function() {
    console.log('socoapi api now listening ...');
  });
});

API

Be sure to URI encode (percent encoding) any query component to a URL.

GET /counts?url=[the url to get share counts for]

Returns share counts for url from all supported vendors.

For example, GET /counts?url=http://www.foobar.baz/%3Fq1%3Dv1%26q2%3Dv2

{
  "facebook" : 1234,
  "google"   : 5317,
  "pinterest": 1,
  "url"      : "http//www.foobar.baz/?q1=v1&q2=v2"
}

GET /counts/:vendor?url=[the url to get share counts for]

Returns share counts for url from supplied :vendor.

For example, GET /counts/facebook?url=http://www.foobar.baz/

{
  "count" : 123
  "vendor" : "facebook"
}

License

MIT

Keywords

FAQs

Last updated on 30 May 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc