3

I have been assigned on a task to fetch all tweets from a certain hashtag and send that data to my application. So I decided to use firebase cloud functions, I generated the key needed for the twitter api. I also tested get my homepage using postman status and worked, however my issue now when I test my code on good cloud functions I cant get it to work and the error message when I try this end point:

Error: could not handle the request

https://us-central1-don.cloudfunctions.net/api/

or

https://us-central1-don.cloudfunctions.net/api/statuses/user_timeline

and this is my code on firebase cloud functions

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');
const Twitter = require('twitter');
admin.initializeApp(functions.config().firebase);



const client = new Twitter({
    consumer_key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    consumer_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    access_token_key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    access_token_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
});

const app = express();

/* Express */

app.get('/', function(req,res){
    client.get('statuses/user_timeline', {screen_name: 'nodejs', count: 5}, function (error, tweets, response) {

        if (!error) {
            response.send({ title: 'Express', tweets: tweets })
        }
        else {
            response.send({ error: "this is error: " + error })
        }
    });
});
// Cloud Function
exports.api = functions.https.onRequest(app)

Hope anyone can suggest any solutions, thanks.

Update: here is my function console where it also throws an error:

api Function execution took 8 ms, finished with status code: 404

api Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions

zuest
  • 167
  • 2
  • 15
  • 1
    Aren't you running the Free plan ? If so, outbound requests are limited to Google's services : https://stackoverflow.com/questions/48680257/firebase-cloud-functions-throws-a-dns-error-when-calling-an-external-api – Philippe Sultan Mar 05 '18 at 10:44
  • @PhilippeSultan yes i am on free plan, thanks for the help, i'll upgrade my account. – zuest Mar 05 '18 at 12:29

1 Answers1

3

As mentioned in the comments, you should upgrade to a paid plan, you may find this other Stack Overflow question useful : Cloud Functions for Firebase - Billing account not configured

Hope this helps!

Philippe Sultan
  • 2,111
  • 17
  • 23
  • thanks, i have not tested the solution yet, but ill mark this is an answer once I do. thanks. – zuest Mar 05 '18 at 12:32