Head over to developer.facebook.com and create an App
On your server, create a facebook webhook that will handle facebook calls. Then create a "leadgen" webhook on you App: https://developers.facebook.com/docs/graph-api/webhooks/v2.5
function shortenNumber(n, d) { | |
if (n < 1) return "<1"; | |
var k = n = Math.floor(n); | |
if (n < 1000) return (n.toString().split("."))[0]; | |
if (d !== 0) d = d || 1; | |
function shorten(a, b, c) { | |
var d = a.toString().split("."); | |
if (!d[1] || b === 0) { | |
return d[0] + c |
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/ | |
function bytesToSize(bytes) { | |
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; | |
if (bytes == 0) return 'n/a'; | |
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); | |
if (i == 0) return bytes + ' ' + sizes[i]; | |
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i]; | |
}; |
Head over to developer.facebook.com and create an App
On your server, create a facebook webhook that will handle facebook calls. Then create a "leadgen" webhook on you App: https://developers.facebook.com/docs/graph-api/webhooks/v2.5
//Here is the curl commands I use to test - make sure you update the CAPSVARS. You can add an item ID Payload or not. | |
//For example if your app displays items, it can navigate to a specific item. | |
//If you want to add more state names, instead of only going to specific items: | |
//add another payload property called 'stateName' | |
//create a goState() function to accept a stateName as a parameter | |
//and modify the registerPush() to find the stateName property and pass into your goState(). | |
//Android | |
curl -u YOURAPIKEY: -H "Content-Type: application/json" -H "X-Ionic-Application-Id: APPID" https://push.ionic.io/api/v1/push -d '{"tokens":["ANDROIDTOKEN"],"notification":{"alert":"I come from planet Ion.", "android":{"title":"This is a title2", "payload":{"sound":"notification.mp3","itemId":"7TF00hJI78Y"}}}}' |
// Credits: Adam's answer in http://stackoverflow.com/a/20786262/69362 | |
var $rootScope = null; | |
if (!$rootScope) $rootScope = angular.element(document).scope(); | |
if (!$rootScope) $rootScope = angular.element(document.querySelectorAll("[ui-view]")[0]).injector().get('$rootScope'); | |
$rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){ | |
console.log('$stateChangeStart to '+toState.to+'- fired when the transition begins. toState,toParams : \n',toState, toParams); | |
}); | |
$rootScope.$on('$stateChangeError',function(event, toState, toParams, fromState, fromParams){ |
//require the Twilio module and create a REST client | |
var client = require('twilio')('ACCOUNT_SID', 'AUTH_TOKEN'); | |
var Firebase = require('firebase'); | |
var fb = new Firebase('FIREBASE_URL'); | |
fb.auth('FIREBASE_SECRET', function(err) { | |
if( err ) { throw err; } | |
listenForEvents(); | |
}) |
// create a class that we will use in place of the pojo (plain old javascript object) | |
// that is normally created in $FirebaseArray | |
function Person(snap) { | |
this.$id = snap.name(); | |
this.updated(snap); | |
} | |
Person.prototype = { | |
updated: function(snap) { | |
this.data = snap.val(); |
var FirebaseService = { | |
init: function(fb) { | |
this.fb = fb; | |
}, | |
pathRef: function(args) { | |
for (var i = 0; i < args.length; i++) { | |
if (angular.isArray(args[i])) { | |
args[i] = this.pathRef(args[i]); | |
} | |
else if (typeof args[i] !== 'string') { |
var app = angular.module('app', ['firebase']); | |
app.controller('ctrl', function($scope, $pageArray) { | |
$scope.pageItems = $pageArray(ref, 'number'); | |
}); | |
app.factory('$pageArray', function($firebaseArray) { | |
return function(ref, field) { | |
// create a Paginate reference | |
var pageRef = new Firebase.util.Paginate(ref, field, {maxCacheSize: 250}); |
I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.
If you want to roll up all of these into a single jQuery plugin check out Sharrre
Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.