Catch up on highlights from Firebase at Google I/O 2023. Learn more

अपने ऐप से कॉल फ़ंक्शन


फायरबेस क्लाइंट एसडीके के लिए क्लाउड फ़ंक्शंस आपको सीधे फायरबेस ऐप से फ़ंक्शन कॉल करने देता है। इस तरह से अपने ऐप से किसी फ़ंक्शन को कॉल करने के लिए, क्लाउड फ़ंक्शंस में एक HTTP कॉल करने योग्य फ़ंक्शन लिखें और तैनात करें, और फिर अपने ऐप से फ़ंक्शन को कॉल करने के लिए क्लाइंट लॉजिक जोड़ें।

यह ध्यान रखना महत्वपूर्ण है कि HTTP कॉल करने योग्य फ़ंक्शन समान हैं लेकिन HTTP फ़ंक्शन के समान नहीं हैं । HTTP कॉल करने योग्य कार्यों का उपयोग करने के लिए आपको बैकएंड एपीआई (या प्रोटोकॉल को लागू करने) के साथ अपने प्लेटफॉर्म के लिए क्लाइंट एसडीके का उपयोग करना होगा। कॉलबलों में HTTP कार्यों से ये महत्वपूर्ण अंतर हैं:

कॉलबलों में HTTP कार्यों से ये महत्वपूर्ण अंतर हैं:

  • कॉलेबल के साथ, Firebase प्रमाणीकरण टोकन, FCM टोकन और ऐप चेक टोकन, जब उपलब्ध हों, स्वचालित रूप से अनुरोधों में शामिल किए जाते हैं।
  • ट्रिगर स्वचालित रूप से अनुरोध निकाय को निष्क्रिय कर देता है और ऑथ टोकन को मान्य करता है।

एचटीटीपीएस कॉल करने योग्य कार्यों का समर्थन करने के लिए क्लाउड फ़ंक्शंस के लिए फायरबेस एसडीके 2nd जीन और उच्चतर इन फायरबेस क्लाइंट एसडीके न्यूनतम संस्करणों के साथ इंटरऑपरेट करता है:

  • Apple प्लेटफॉर्म 10.10.0 के लिए Firebase SDK
  • Android 20.3.1 के लिए फायरबेस एसडीके
  • फायरबेस मॉड्यूलर वेब एसडीके v. 9.7.0

यदि आप किसी असमर्थित प्लेटफ़ॉर्म पर निर्मित ऐप में समान कार्यक्षमता जोड़ना चाहते हैं, तो https.onCall के लिए प्रोटोकॉल विशिष्टता देखें। इस गाइड के बाकी हिस्सों में ऐप्पल प्लेटफॉर्म, एंड्रॉइड, वेब, सी ++ और यूनिटी के लिए HTTP कॉल करने योग्य फ़ंक्शन को लिखने, तैनात करने और कॉल करने के निर्देश दिए गए हैं।

कॉल करने योग्य फ़ंक्शन लिखें और तैनात करें

HTTPS कॉल करने योग्य फ़ंक्शन बनाने के लिए functions.https.onCall उपयोग करें। यह विधि दो पैरामीटर लेती है: data और वैकल्पिक context :

// Saves a message to the Firebase Realtime Database but sanitizes the text by removing swearwords.
exports.addMessage = functions.https.onCall((data, context) => {
  // ...
});

एक कॉल करने योग्य फ़ंक्शन के लिए जो रीयलटाइम डेटाबेस में टेक्स्ट संदेश सहेजता है, उदाहरण के लिए, data में संदेश टेक्स्ट हो सकता है, जबकि context पैरामीटर उपयोगकर्ता की जानकारी का प्रतिनिधित्व करते हैं:

// Message text passed from the client.
const text = data.text;
// Authentication / user information is automatically added to the request.
const uid = context.auth.uid;
const name = context.auth.token.name || null;
const picture = context.auth.token.picture || null;
const email = context.auth.token.email || null;

कॉल करने योग्य फ़ंक्शन के स्थान और कॉलिंग क्लाइंट के स्थान के बीच की दूरी नेटवर्क विलंबता बना सकती है। प्रदर्शन को अनुकूलित करने के लिए, जहां लागू हो, फ़ंक्शन स्थान निर्दिष्ट करने पर विचार करें, और कॉल करने योग्य स्थान को स्थान सेट के साथ संरेखित करना सुनिश्चित करें जब आप क्लाइंट साइड पर एसडीके प्रारंभ करते हैं

वैकल्पिक रूप से, आप अपने बैकएंड संसाधनों को बिलिंग धोखाधड़ी या फ़िशिंग जैसे दुरुपयोग से बचाने में सहायता के लिए ऐप चेक सत्यापन संलग्न कर सकते हैं। क्लाउड फ़ंक्शंस के लिए ऐप चेक प्रवर्तन सक्षम करें देखें।

परिणाम वापस भेज रहा हूँ

क्लाइंट को डेटा वापस भेजने के लिए, वह डेटा वापस करें जो JSON एनकोडेड हो सकता है। उदाहरण के लिए, एक अतिरिक्त ऑपरेशन का परिणाम वापस करने के लिए:

// returning result.
return {
  firstNumber: firstNumber,
  secondNumber: secondNumber,
  operator: '+',
  operationResult: firstNumber + secondNumber,
};

एसिंक्रोनस ऑपरेशन के बाद डेटा वापस करने के लिए, एक वादा वापस करें। प्रॉमिस द्वारा लौटाया गया डेटा क्लाइंट को वापस भेज दिया जाता है। उदाहरण के लिए, आप कॉल करने योग्य फ़ंक्शन द्वारा रीयलटाइम डेटाबेस को लिखा गया स्वच्छ टेक्स्ट वापस कर सकते हैं:

// Saving the new message to the Realtime Database.
const sanitizedMessage = sanitizer.sanitizeText(text); // Sanitize the message.
return admin.database().ref('/messages').push({
  text: sanitizedMessage,
  author: { uid, name, picture, email },
}).then(() => {
  console.log('New Message written');
  // Returning the sanitized message to the client.
  return { text: sanitizedMessage };
})

त्रुटियों को संभालें

यह सुनिश्चित करने के लिए कि क्लाइंट को उपयोगी एरर डिटेल्स मिले, फंक्शंस. functions.https.HttpsError का एक इंस्टेंस फेंक कर (या रिजेक्ट किए गए प्रॉमिस को रिटर्न करके) कॉलेबल से एरर रिटर्न करें। त्रुटि में एक code विशेषता है जो functions.https.HttpsError पर सूचीबद्ध मानों में से एक हो सकती है। त्रुटियों में एक स्ट्रिंग message भी होता है, जो एक खाली स्ट्रिंग के लिए डिफ़ॉल्ट होता है। उनके पास मनमाने मूल्य के साथ एक वैकल्पिक details फ़ील्ड भी हो सकता है। यदि आपके कार्यों से HttpsError के अलावा कोई त्रुटि फेंक दी जाती है, तो आपके क्लाइंट को INTERNAL संदेश और internal कोड के साथ एक त्रुटि प्राप्त होती है।

उदाहरण के लिए, एक फ़ंक्शन कॉलिंग क्लाइंट पर लौटने के लिए त्रुटि संदेशों के साथ डेटा सत्यापन और प्रमाणीकरण त्रुटियों को फेंक सकता है:

// Checking attribute.
if (!(typeof text === 'string') || text.length === 0) {
  // Throwing an HttpsError so that the client gets the error details.
  throw new functions.https.HttpsError('invalid-argument', 'The function must be called with ' +
      'one arguments "text" containing the message text to add.');
}
// Checking that the user is authenticated.
if (!context.auth) {
  // Throwing an HttpsError so that the client gets the error details.
  throw new functions.https.HttpsError('failed-precondition', 'The function must be called ' +
      'while authenticated.');
}

कॉल करने योग्य फ़ंक्शन को परिनियोजित करें

आपके द्वारा index.js के भीतर एक पूर्ण कॉल करने योग्य फ़ंक्शन को सहेजने के बाद, जब आप firebase deploy चलाते हैं तो इसे अन्य सभी कार्यों के साथ तैनात किया जाता है। केवल कॉल करने योग्य परिनियोजित करने के लिए, --only तर्क का उपयोग करें, जैसा कि आंशिक तैनाती करने के लिए दिखाया गया है:

firebase deploy --only functions:addMessage

यदि आप कार्यों की तैनाती करते समय अनुमतियों की त्रुटियों का सामना करते हैं, तो सुनिश्चित करें कि उपयुक्त IAM भूमिकाएँ परिनियोजन कमांड चलाने वाले उपयोगकर्ता को सौंपी गई हैं।

अपना ग्राहक विकास वातावरण सेट करें

सुनिश्चित करें कि आप किसी भी पूर्वापेक्षा को पूरा करते हैं, फिर अपने ऐप में आवश्यक निर्भरताएँ और क्लाइंट लाइब्रेरी जोड़ें।

आईओएस+

अपने Apple ऐप में Firebase को जोड़ने के लिए निर्देशों का पालन करें।

फायरबेस निर्भरताओं को स्थापित और प्रबंधित करने के लिए स्विफ्ट पैकेज मैनेजर का उपयोग करें।

  1. Xcode में, अपने ऐप प्रोजेक्ट को खोलने के साथ, File > Add Packages पर नेविगेट करें।
  2. संकेत दिए जाने पर, Firebase Apple प्लेटफ़ॉर्म SDK रिपॉजिटरी जोड़ें:
  3.   https://github.com/firebase/firebase-ios-sdk
  4. क्लाउड फ़ंक्शंस लाइब्रेरी चुनें।
  5. समाप्त होने पर, Xcode स्वचालित रूप से पृष्ठभूमि में आपकी निर्भरताओं को हल करना और डाउनलोड करना शुरू कर देगा।

Web modular API

  1. Firebase को अपने वेब ऐप में जोड़ने के लिए निर्देशों का पालन करें। अपने टर्मिनल से निम्न कमांड चलाना सुनिश्चित करें:
    npm install firebase@9.22.1 --save
    
  2. मैन्युअल रूप से फायरबेस कोर और क्लाउड फ़ंक्शंस दोनों की आवश्यकता होती है:

     import { initializeApp } from 'firebase/app';
     import { getFunctions } from 'firebase/functions';
    
     const app = initializeApp({
         projectId: '### CLOUD FUNCTIONS PROJECT ID ###',
         apiKey: '### FIREBASE API KEY ###',
         authDomain: '### FIREBASE AUTH DOMAIN ###',
       });
     const functions = getFunctions(app);
    

Web namespaced API

  1. Firebase को अपने वेब ऐप में जोड़ने के लिए निर्देशों का पालन करें।
  2. अपने ऐप में फायरबेस कोर और क्लाउड फ़ंक्शंस क्लाइंट लाइब्रेरी जोड़ें:
    <script src="https://www.gstatic.com/firebasejs/8.10.1/firebase.js"></script>
    <script src="https://www.gstatic.com/firebasejs/8.10.1/firebase-functions.js"></script>
    

क्लाउड फ़ंक्शंस SDK एक npm पैकेज के रूप में भी उपलब्ध है।

  1. अपने टर्मिनल से निम्न कमांड चलाएँ:
    npm install firebase@8.10.1 --save
    
  2. मैन्युअल रूप से फायरबेस कोर और क्लाउड फ़ंक्शंस दोनों की आवश्यकता होती है:
    const firebase = require("firebase");
    // Required for side-effects
    require("firebase/functions");
    

Kotlin+KTX

  1. अपने Android ऐप में Firebase को जोड़ने के लिए निर्देशों का पालन करें।

  2. अपने मॉड्यूल (ऐप-लेवल) ग्रैडल फ़ाइल (आमतौर पर <project>/<app-module>/build.gradle ) में, क्लाउड फ़ंक्शंस एंड्रॉइड लाइब्रेरी के लिए निर्भरता जोड़ें। हम लाइब्रेरी वर्ज़निंग को नियंत्रित करने के लिए Firebase Android BoM का उपयोग करने की सलाह देते हैं।

    dependencies {
        // Import the BoM for the Firebase platform
        implementation platform('com.google.firebase:firebase-bom:32.1.0')
    
        // Add the dependency for the Cloud Functions library
        // When using the BoM, you don't specify versions in Firebase library dependencies
        implementation 'com.google.firebase:firebase-functions-ktx'
    }
    

    Firebase Android BoM का उपयोग करके, आपका ऐप हमेशा Firebase Android पुस्तकालयों के संगत संस्करणों का उपयोग करेगा।

    (वैकल्पिक) BoM का उपयोग किए बिना Firebase लाइब्रेरी निर्भरताएँ जोड़ें

    यदि आप Firebase BoM का उपयोग नहीं करना चुनते हैं, तो आपको प्रत्येक Firebase लाइब्रेरी संस्करण को उसकी निर्भरता रेखा में निर्दिष्ट करना होगा।

    ध्यान दें कि यदि आप अपने ऐप में एकाधिक फायरबेस लाइब्रेरी का उपयोग करते हैं, तो हम लाइब्रेरी संस्करणों को प्रबंधित करने के लिए बीओएम का उपयोग करने की दृढ़ता से अनुशंसा करते हैं, जो सुनिश्चित करता है कि सभी संस्करण संगत हैं।

    dependencies {
        // Add the dependency for the Cloud Functions library
        // When NOT using the BoM, you must specify versions in Firebase library dependencies
        implementation 'com.google.firebase:firebase-functions-ktx:20.3.1'
    }
    

Java

  1. अपने Android ऐप में Firebase को जोड़ने के लिए निर्देशों का पालन करें।

  2. अपने मॉड्यूल (ऐप-लेवल) ग्रैडल फ़ाइल (आमतौर पर <project>/<app-module>/build.gradle ) में, क्लाउड फ़ंक्शंस एंड्रॉइड लाइब्रेरी के लिए निर्भरता जोड़ें। हम लाइब्रेरी वर्ज़निंग को नियंत्रित करने के लिए Firebase Android BoM का उपयोग करने की सलाह देते हैं।

    dependencies {
        // Import the BoM for the Firebase platform
        implementation platform('com.google.firebase:firebase-bom:32.1.0')
    
        // Add the dependency for the Cloud Functions library
        // When using the BoM, you don't specify versions in Firebase library dependencies
        implementation 'com.google.firebase:firebase-functions'
    }
    

    Firebase Android BoM का उपयोग करके, आपका ऐप हमेशा Firebase Android पुस्तकालयों के संगत संस्करणों का उपयोग करेगा।

    (वैकल्पिक) BoM का उपयोग किए बिना Firebase लाइब्रेरी निर्भरताएँ जोड़ें

    यदि आप Firebase BoM का उपयोग नहीं करना चुनते हैं, तो आपको प्रत्येक Firebase लाइब्रेरी संस्करण को उसकी निर्भरता रेखा में निर्दिष्ट करना होगा।

    ध्यान दें कि यदि आप अपने ऐप में एकाधिक फायरबेस लाइब्रेरी का उपयोग करते हैं, तो हम लाइब्रेरी संस्करणों को प्रबंधित करने के लिए बीओएम का उपयोग करने की दृढ़ता से अनुशंसा करते हैं, जो सुनिश्चित करता है कि सभी संस्करण संगत हैं।

    dependencies {
        // Add the dependency for the Cloud Functions library
        // When NOT using the BoM, you must specify versions in Firebase library dependencies
        implementation 'com.google.firebase:firebase-functions:20.3.1'
    }
    

Dart

  1. Firebase को अपने Flutter ऐप में जोड़ने के लिए निर्देशों का पालन करें।

  2. अपने स्पंदन प्रोजेक्ट की जड़ से, प्लगइन स्थापित करने के लिए निम्नलिखित कमांड चलाएँ:

    flutter pub add cloud_functions
    
  3. एक बार पूरा हो जाने पर, अपने स्पंदन एप्लिकेशन का पुनर्निर्माण करें:

    flutter run
    
  4. एक बार इंस्टॉल हो जाने पर, आप cloud_functions प्लगइन को अपने डार्ट कोड में आयात करके एक्सेस कर सकते हैं:

    import 'package:cloud_functions/cloud_functions.dart';
    

सी ++

Android के साथ C++ के लिए:

  1. अपने C++ प्रोजेक्ट में Firebase को जोड़ने के लिए निर्देशों का पालन करें।
  2. firebase_functions लाइब्रेरी को अपनी CMakeLists.txt फ़ाइल में जोड़ें।

Apple प्लेटफॉर्म के साथ C++ के लिए:

  1. अपने C++ प्रोजेक्ट में Firebase को जोड़ने के लिए निर्देशों का पालन करें।
  2. क्लाउड फ़ंक्शंस पॉड को अपने Podfile में जोड़ें:
    pod 'Firebase/Functions'
  3. फ़ाइल सहेजें, फिर चलाएँ:
    pod install
  4. अपने Xcode प्रोजेक्ट में Firebase C++ SDK से Firebase कोर और क्लाउड फ़ंक्शंस फ्रेमवर्क जोड़ें।
    • firebase.framework
    • firebase_functions.framework

एकता

  1. अपने यूनिटी प्रोजेक्ट में Firebase को जोड़ने के लिए निर्देशों का पालन करें।
  2. Firebase यूनिटी SDK से FirebaseFunctions.unitypackage को अपने यूनिटी प्रोजेक्ट में जोड़ें।

क्लाइंट SDK को इनिशियलाइज़ करें

क्लाउड फ़ंक्शंस का एक उदाहरण प्रारंभ करें:

तीव्र

lazy var functions = Functions.functions()

उद्देश्य सी

@property(strong, nonatomic) FIRFunctions *functions;
// ...
self.functions = [FIRFunctions functions];

Web namespaced API

firebase.initializeApp({
  apiKey: '### FIREBASE API KEY ###',
  authDomain: '### FIREBASE AUTH DOMAIN ###',
  projectId: '### CLOUD FUNCTIONS PROJECT ID ###'
  databaseURL: 'https://### YOUR DATABASE NAME ###.firebaseio.com',
});

// Initialize Cloud Functions through Firebase
var functions = firebase.functions();

Web modular API

const app = initializeApp({
  projectId: '### CLOUD FUNCTIONS PROJECT ID ###',
  apiKey: '### FIREBASE API KEY ###',
  authDomain: '### FIREBASE AUTH DOMAIN ###',
});
const functions = getFunctions(app);

Kotlin+KTX

private lateinit var functions: FirebaseFunctions
// ...
functions = Firebase.functions

Java

private FirebaseFunctions mFunctions;
// ...
mFunctions = FirebaseFunctions.getInstance();

Dart

final functions = FirebaseFunctions.instance;

सी ++

firebase::functions::Functions* functions;
// ...
functions = firebase::functions::Functions::GetInstance(app);

एकता

functions = Firebase.Functions.DefaultInstance;

समारोह को बुलाओ

तीव्र

functions.httpsCallable("addMessage").call(["text": inputField.text]) { result, error in
  if let error = error as NSError? {
    if error.domain == FunctionsErrorDomain {
      let code = FunctionsErrorCode(rawValue: error.code)
      let message = error.localizedDescription
      let details = error.userInfo[FunctionsErrorDetailsKey]
    }
    // ...
  }
  if let data = result?.data as? [String: Any], let text = data["text"] as? String {
    self.resultField.text = text
  }
}

उद्देश्य सी

[[_functions HTTPSCallableWithName:@"addMessage"] callWithObject:@{@"text": _inputField.text}
                                                      completion:^(FIRHTTPSCallableResult * _Nullable result, NSError * _Nullable error) {
  if (error) {
    if ([error.domain isEqual:@"com.firebase.functions"]) {
      FIRFunctionsErrorCode code = error.code;
      NSString *message = error.localizedDescription;
      NSObject *details = error.userInfo[@"details"];
    }
    // ...
  }
  self->_resultField.text = result.data[@"text"];
}];

Web namespaced API

var addMessage = firebase.functions().httpsCallable('addMessage');
addMessage({ text: messageText })
  .then((result) => {
    // Read result of the Cloud Function.
    var sanitizedMessage = result.data.text;
  });

Web modular API

import { getFunctions, httpsCallable } from "firebase/functions";

const functions = getFunctions();
const addMessage = httpsCallable(functions, 'addMessage');
addMessage({ text: messageText })
  .then((result) => {
    // Read result of the Cloud Function.
    /** @type {any} */
    const data = result.data;
    const sanitizedMessage = data.text;
  });

Kotlin+KTX

private fun addMessage(text: String): Task<String> {
    // Create the arguments to the callable function.
    val data = hashMapOf(
        "text" to text,
        "push" to true,
    )

    return functions
        .getHttpsCallable("addMessage")
        .call(data)
        .continueWith { task ->
            // This continuation runs on either success or failure, but if the task
            // has failed then result will throw an Exception which will be
            // propagated down.
            val result = task.result?.data as String
            result
        }
}

Java

private Task<String> addMessage(String text) {
    // Create the arguments to the callable function.
    Map<String, Object> data = new HashMap<>();
    data.put("text", text);
    data.put("push", true);

    return mFunctions
            .getHttpsCallable("addMessage")
            .call(data)
            .continueWith(new Continuation<HttpsCallableResult, String>() {
                @Override
                public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {
                    // This continuation runs on either success or failure, but if the task
                    // has failed then getResult() will throw an Exception which will be
                    // propagated down.
                    String result = (String) task.getResult().getData();
                    return result;
                }
            });
}

Dart

    final result = await FirebaseFunctions.instance.httpsCallable('addMessage').call(
      {
        "text": text,
        "push": true,
      },
    );
    _response = result.data as String;

सी ++

firebase::Future<firebase::functions::HttpsCallableResult> AddMessage(
    const std::string& text) {
  // Create the arguments to the callable function.
  firebase::Variant data = firebase::Variant::EmptyMap();
  data.map()["text"] = firebase::Variant(text);
  data.map()["push"] = true;

  // Call the function and add a callback for the result.
  firebase::functions::HttpsCallableReference doSomething =
      functions->GetHttpsCallable("addMessage");
  return doSomething.Call(data);
}

एकता

private Task<string> addMessage(string text) {
  // Create the arguments to the callable function.
  var data = new Dictionary<string, object>();
  data["text"] = text;
  data["push"] = true;

  // Call the function and extract the operation from the result.
  var function = functions.GetHttpsCallable("addMessage");
  return function.CallAsync(data).ContinueWith((task) => {
    return (string) task.Result.Data;
  });
}

क्लाइंट पर त्रुटियों को संभालें

यदि सर्वर ने कोई त्रुटि फेंकी या परिणामी वादे को अस्वीकार कर दिया गया तो क्लाइंट को एक त्रुटि प्राप्त होती है।

यदि फ़ंक्शन द्वारा लौटाई गई त्रुटि function.https.HttpsError प्रकार की है, तो क्लाइंट को सर्वर त्रुटि से त्रुटि code , message और details प्राप्त होता है। अन्यथा, त्रुटि में संदेश INTERNAL और कोड INTERNAL होता है। अपने कॉल करने योग्य फ़ंक्शन में त्रुटियों को कैसे प्रबंधित करें , इसके लिए मार्गदर्शन देखें।

तीव्र

if let error = error as NSError? {
  if error.domain == FunctionsErrorDomain {
    let code = FunctionsErrorCode(rawValue: error.code)
    let message = error.localizedDescription
    let details = error.userInfo[FunctionsErrorDetailsKey]
  }
  // ...
}

उद्देश्य सी

if (error) {
  if ([error.domain isEqual:@"com.firebase.functions"]) {
    FIRFunctionsErrorCode code = error.code;
    NSString *message = error.localizedDescription;
    NSObject *details = error.userInfo[@"details"];
  }
  // ...
}

Web namespaced API

var addMessage = firebase.functions().httpsCallable('addMessage');
addMessage({ text: messageText })
  .then((result) => {
    // Read result of the Cloud Function.
    var sanitizedMessage = result.data.text;
  })
  .catch((error) => {
    // Getting the Error details.
    var code = error.code;
    var message = error.message;
    var details = error.details;
    // ...
  });

Web modular API

import { getFunctions, httpsCallable } from "firebase/functions";

const functions = getFunctions();
const addMessage = httpsCallable(functions, 'addMessage');
addMessage({ text: messageText })
  .then((result) => {
    // Read result of the Cloud Function.
    /** @type {any} */
    const data = result.data;
    const sanitizedMessage = data.text;
  })
  .catch((error) => {
    // Getting the Error details.
    const code = error.code;
    const message = error.message;
    const details = error.details;
    // ...
  });

Kotlin+KTX

addMessage(inputMessage)
    .addOnCompleteListener { task ->
        if (!task.isSuccessful) {
            val e = task.exception
            if (e is FirebaseFunctionsException) {
                val code = e.code
                val details = e.details
            }
        }
    }

Java

addMessage(inputMessage)
        .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();
                    }
                }
            }
        });

Dart

try {
  final result =
      await FirebaseFunctions.instance.httpsCallable('addMessage').call();
} on FirebaseFunctionsException catch (error) {
  print(error.code);
  print(error.details);
  print(error.message);
}

सी ++

void OnAddMessageCallback(
    const firebase::Future<firebase::functions::HttpsCallableResult>& future) {
  if (future.error() != firebase::functions::kErrorNone) {
    // Function error code, will be kErrorInternal if the failure was not
    // handled properly in the function call.
    auto code = static_cast<firebase::functions::Error>(future.error());

    // Display the error in the UI.
    DisplayError(code, future.error_message());
    return;
  }

  const firebase::functions::HttpsCallableResult* result = future.result();
  firebase::Variant data = result->data();
  // This will assert if the result returned from the function wasn't a string.
  std::string message = data.string_value();
  // Display the result in the UI.
  DisplayResult(message);
}

// ...

// ...
  auto future = AddMessage(message);
  future.OnCompletion(OnAddMessageCallback);
  // ...

एकता

 addMessage(text).ContinueWith((task) => {
  if (task.IsFaulted) {
    foreach (var inner in task.Exception.InnerExceptions) {
      if (inner is FunctionsException) {
        var e = (FunctionsException) inner;
        // Function error code, will be INTERNAL if the failure
        // was not handled properly in the function call.
        var code = e.ErrorCode;
        var message = e.ErrorMessage;
      }
    }
  } else {
    string result = task.Result;
  }
});

अपना ऐप लॉन्च करने से पहले, आपको यह सुनिश्चित करने में सहायता के लिए ऐप चेक सक्षम करना चाहिए कि केवल आपके ऐप ही आपके कॉल करने योग्य फ़ंक्शन एंडपॉइंट तक पहुंच सकते हैं।