Google Firebase Cloud Functions:Android 应用调用 `siteverify` 的后端实际上需要使用结算帐户

Google Firebase Cloud Functions: Android app's call to backend which calls `siteverify` actually requires a billing account to be used

我使用 Google Firebase Cloud Functions 托管以下脚本来检查输入我的 Android 应用程序用户的 ReCaptcha 是否正确。这个想法是,在用户输入验证码后,应用程序调用 Cloud Functions 的脚本(托管在 Google 服务器中)。后者然后通过 POST 请求称自己为以下 URL:https://www.google.com/recaptcha/api/siteverify.

问题:在 Google 服务器的日志中,我发现了以下错误:

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

Error: Error: getaddrinfo EAI_AGAIN www.google.com:443
    at Request._callback (/srv/index.js:20:10)
    at self.callback (/srv/node_modules/request/request.js:185:22)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at Request.onRequestError (/srv/node_modules/request/request.js:881:8)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at TLSSocket.socketErrorListener (_http_client.js:401:9)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)

托管在 Google Cloud Functions 服务器中的后端脚本如下:

const functions = require('firebase-functions');
const request2 = require('request');

/**
 * Verifies a Recaptcha filled by the user in his Android app.
 * 1. Success: returns the JSON response
 * 2. Failure: throws the error
 **/
exports.verifyRecaptcha = functions.https.onRequest((request, response) => {

    const user_response_token = request.query.user_response_token;
    if(user_response_token === '') {
        throw new functions.https.HttpsError('invalid-argument', 'The function must be called with an adequat user response token.');
    }

    const remote_url = 'https://www.google.com/recaptcha/api/siteverify';
    const secret = '';
    request2.post({url: remote_url, form:{secret: secret, response: user_response_token}}, function(error, response, body) {
        if(error) {
            throw new functions.https.HttpsError('unknown', error);
        }

        if(!response.statusCode !== 200) {
            throw new functions.https.HttpsError('unknown', 'Something went wrong. Status code: ' + response.statusCode + '.');
        }

        if(!body.success) {
            throw new functions.https.HttpsError('unknown', 'Unable to verify this captcha.');
        }

        return response;
    });

});

我的问题是:有没有什么方法可以请求此 URL 而无需创建结算帐户?

编辑:正如弗兰克在评论中指出的那样,我错过了这是一个内部 URL,并且始终显示免费计划的消息,即使尽管请求应该有效。如果请求不起作用,则应提交错误。

我的回答是针对非Google(例如外部)URL,我将在下面保留它(因为它允许您在解决错误时绕过检查).


没有。您需要一个计费帐户才能从 Cloud Functions 发出外部网络请求。见 Cloud Functions Section of the pricing page.

不过,只需配置一个计费帐户,您仍然可以利用 Spark 计划的免费套餐限制。仅进行外部网络请求不会产生实际成本。