Google Firebase Cloud Functions:Android应用程序对后端的调用(称为`siteverify`,实际上需要使用计费帐户)

问题描述 投票:0回答:1

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

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

未配置结算帐户。无法访问外部网络,并且配额受到严格限制。配置结算帐户以消除这些限制

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?

android firebase google-cloud-functions recaptcha
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.