Google Cloud Function that returns the number of followers a given handle has, or -1 if it can't get them. Example response:
{
"followers": 1001
}
Example code to call this, using JavaScript fetch
API:
const myHeaders = new Headers();
myHeaders.append('x-api-key', '<api key>');
const requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch('https://<cloud function url>/getFollowers?handle=<twitter handle>', requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Where:
<api key>
is the value of theAPI_KEY
environment variable for your deployed funtion (see below).<cloud function url>
is the Google Cloud URL for your deployed function.<twitter handle>
is the Twitter handle you want to get the number of followers for, for example mine issimon_prickett
.
When deploying to Google Cloud Functions, add the following environment variable:
API_KEY
- set to whatever value you want to use, then provide that value in thex-api-key
header when calling the function.TWITTER_BEARER_TOKEN
- set to a Twitter API bearer token for the Twitter API v2.