-
Notifications
You must be signed in to change notification settings - Fork 16
4. Share Counts
To count the number of times a URL has been shared, simply initialize a count node specifying the URL and the platform(s) to count on.
<span data-open-share-count="facebook" data-open-share-count-url="http://www.digitalsurgeons.com"></span>
<span data-open-share-count="facebook,pinterest,reddit" data-open-share-count-url="http://www.digitalsurgeons.com"></span>
or, with JavaScript:
new OpenShare.count({
type: 'facebook',
url: 'http://openshare.social',
appendTo: document.body
}, node => {
console.log(`OpenShare has been shared on Facebook ${node.innerHTML} times!`)
node.style.color = 'blue'
})
in 2015, Twitter announced the deprecation of their count API. We have built a solution to this by querying Twitter's Search API for a URL and counting the number of results. In order to do this and stay within API rate limits we need to query the Search API on your behalf.
Connect your Twitter account with OpenShare, create a new Twitter application and pass us your access tokens. Once you have done this and specified the URLs you would like to count you will receive an API key, simply pass this to the count nodes and voila, you have Twitter share counts back! More detailed instructions can be found at openshare.social.
<span data-open-share-count="twitter"
data-open-share-count-url='http://yourwebsite.com/'
data-open-share-key="yourkey"></span>
or, with JavaScript
const OpenShare = require('openshare');
OpenShare.count({
type: 'twitter',
url: 'http://yourwebsite.com/',
key: 'yourkey'
});