Skip to content

Instantly share code, notes, and snippets.

@hamedbaatour
Created August 4, 2019 20:37
Show Gist options
  • Save hamedbaatour/0a8237f37861091432cd0c9ae3167fc5 to your computer and use it in GitHub Desktop.
Save hamedbaatour/0a8237f37861091432cd0c9ae3167fc5 to your computer and use it in GitHub Desktop.
const functions = require('firebase-functions');
// environment variables
require("dotenv").config();
/**⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘
* @Twitter
* ⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘⌘
**/
exports.tweets = functions.https.onCall(async (body, context) => {
try {
const Twitter = require('twitter');
const client = new Twitter({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
});
const params = {q: body.q, count: 10};
return await new Promise((resolve, reject) => {
client.get('search/tweets', params, function (error, tweets, response) {
if (!error) {
return resolve(tweets);
} else {
return reject(error)
}
});
});
} catch (e) {
console.error(e);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment