Demo of the friendship paradox via Twitter social network. The friendship paradox states "most people have fewer friends than their friends do." This is true for most social graphs because popular people will push more people below the average.
- A Firebase account with billing enabled. Billing must be enabled to call third party APIs like twitter.com.
- The latest copy of the
firebase-tools
. - A Twitter app. You can create one at apps.twitter.com.
- Clone this repo.
- Set
firebase-tools
to use your project withfirebase use <YOUR_PROJECT>
- Use
firebase functions:config:set
to settwitter.consumer_secret
,twitter.consumer_key
,twitter.access_token_secret
, andtwitter.access_token_key
. You can get these values from apps.twitter.com - Deploy with
firebase deploy
firebase deploy
will print out the URL of your http function (it will end with "/rating")- Go to this URL. It expects the query parameter "?username="
- Make a local copy of your runtime config by running the following command from your
functions
directory:firebase functions:config:get > .runtimeconfig.json
(We highly recommend you include this file in your.gitignore
) - Start the functions shell with
firebase experimental:functions:shell
or create a local HTTP server for therating
function withfirebase serve --only functions
This is just a tech demo so a number of corners were cut to save time or make code more readable:
- This program will only analyze a user's first 5000 followers. Support for more followers requires pagination support in the getFollowers helper method.
- This program hard codes all API calls to be made against a single user. A better option would be to use application-level credentials. This requires a manual OAuth call with the
twitter
node module. It comes automatically in thetwit
node module, but this SDK has a much more verbose return type and makes the rest of the code less readable. The best option would be to accept Twitter OAuth tokens in therating
function's Authentication header and use that for Twitter API calls.