调用条带化API的Callable Cloud Function始终返回null

我遇到了一个问题,即我的客户端应用程序未提取可调用云函数返回的结果。至少从我的判断来看,云功能一直在起作用,但我在应用程序中只看到空结果。

在应用程序内部,当我尝试将其打印到控制台时,它为空白并停止了该应用程序,并说PrintLN需要消息。我不知道有什么其他方法可以查看应用程序是否正在接收返回数据。

我所有的逻辑都在云中进行,我正在尝试将数据条ID重新带回我的应用程序,因此可以将其保存到首选项中,以备后用。因此,Stripe ID是我唯一需要返回到客户端的东西。

这是云功能:

exports.customerSignupApp = functions.https.onCall(async (data,context) => {
    const email = data.email;
    const password = data.password;
    const firstname = data.firstname;
    const lastname = data.lastname;
    const mobile = data.mobile;

    //console.log('Console Body:',data);

    admin.auth().createUser({
        email: email,emailVerified: false,phoneNumber: mobile,password: password,displayName: firstname + ' ' + lastname,disabled: false
    })
        .then(async function (userRecord) {
            console.log('User record:',userRecord);

            var userObject =
            {
                first_name: firstname,last_name: lastname,mobile_number: mobile,email: email,timestamp: admin.database.ServerValue.TIMESTAMP,driver_profile: { isDriverApproved: false,isDriverDisabled: false,isDriverStatusPending: false,isDriver: false,isPickupModeEnabled: false },}
            stripe.customers.create({
                description: 'Firebase ID: ' + userRecord.uid,email: userRecord.email,name: userRecord.displayName,phone: userRecord.phoneNumber

            },async function (err,customer) {
                console.log('New Stripe ID Created',customer.id);
                try {
                    userObject["stripe_id"] = customer.id;
                    await admin.database().ref('users/' + userRecord.uid).set(userObject);
                    const msg = {
                        to: [userRecord.email],from: {
                            email: 'noreply@noreply.com',name: 'REDactED'
                        },// custom templates
                        templateId: 'dlkhfjdslkfjsdlkfj',substitutionWrappers: ['{{','}}'],dynamic_template_data: {
                            name: userRecord.displayName
                        }
                    };
                    await sgMail.send(msg);
                    console.log('Return Data:',userObject["stripe_id"] )
                    return { stripeId: userObject["stripe_id"] };
                } catch (error) {
                    console.error(error);
                    throw new functions.https.HttpsError('unknown',error.message,error);
                }
            });
        })
        .catch(function (error) {
            console.log('Error creating new user:',error);
            throw new functions.https.HttpsError('unknown',error);
        });
});

这是Android Studio中的功能和任务:

protected void signUserup(String email,String password,String firstname,String lastname) {
        formatE164Number("US",mMobileField.getText().toString());
        signUserupTask(email,password,firstname,lastname,mobileNumber)
                .addOnCompleteListener(new OnCompleteListener<String>() {
                    @Override
                    public void onComplete(@NonNull Task<String> task) {
                       if (!task.isSuccessful()) {
                          Exception e = task.getException();
                           if (e instanceof FirebaseFunctionsException) {
                               FirebaseFunctionsException ffe = (FirebaseFunctionsException) e;
                              FirebaseFunctionsException.Code code = ffe.getcode();
                              Object details = ffe.getDetails();
                          }
                          Log.d("Message Failer",e.toString());
                            snackbar snackbar = snackbar.make(findViewById(android.R.id.content),"An error has occured,please try again.",snackbar.LENGTH_LONG);
                           snackbar.show();
                          return;
                    }


                        Intent intent = new Intent(SignUpactivity.this,CustomerMainNavigationactivity.class);
                        startactivity(intent);
                  }
                });
    }

    private Task<String> signUserupTask(String email,String lastname,String phone) {
        Map<String,Object> data = new HashMap<>();
        data.put("email",email);
        data.put("password",password);
        data.put("firstname",firstname);
        data.put("lastname",lastname);
        data.put("mobile",phone);

        return mFunctions
                .getHttpsCallable("customerSignupApp")
                .call(data)
                .continueWith(new Continuation<HttpsCallableResult,String>() {
                    @Override
                    public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {
                        String result = (String) task.getResult().getData();
                        //Log.d(TAG,"Result in callable callback: " + result);
                        Log.d("Result of FB",result);

//                       SharedPreferences preferences = context.getSharedPreferences("MyPreferences",Context.MODE_PRIVATE);
//                       SharedPreferences.Editor editor = preferences.edit();
//                       editor.putString("stripeID",result);
//                       editor.commit();

                        return result;

                    }
                });
    }
chenelaine 回答:调用条带化API的Callable Cloud Function始终返回null

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3169622.html

大家都在问