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


'Firebase के लिए Cloud Functions' क्लाइंट SDK टूल की मदद से, फ़ंक्शन को सीधे Firebase ऐप्लिकेशन. अपने ऐप्लिकेशन से इस तरीके से फ़ंक्शन कॉल करने के लिए, लिखें और डिप्लॉय करें Cloud Functions में एचटीटीपी कॉल करने लायक फ़ंक्शन है और इसके बाद, अपने ऐप्लिकेशन से फ़ंक्शन को कॉल करने के लिए क्लाइंट लॉजिक जोड़ें.

यह ध्यान रखना ज़रूरी है कि एचटीटीपी कॉल करने लायक फ़ंक्शन एक जैसे होते हैं, लेकिन जो एचटीटीपी फ़ंक्शन के जैसा नहीं है. एचटीटीपी कॉल करने लायक फ़ंक्शन का इस्तेमाल करने के लिए अपने प्लैटफ़ॉर्म के लिए क्लाइंट SDK टूल का इस्तेमाल बैकएंड एपीआई (या प्रोटोकॉल लागू करना). कॉल किए जा सकने वाले डिवाइसों में ये कुंजी होती हैं एचटीटीपी फ़ंक्शन से अंतर:

  • कॉल किए जा सकने वाले एलिमेंट के साथ, Firebase से पुष्टि करने वाले टोकन, FCM टोकन, और ऐप्लिकेशन चेक टोकन उपलब्ध होने पर, उन्हें अपने-आप अनुरोधों में शामिल कर लिया जाता है.
  • ट्रिगर, अनुरोध के मुख्य हिस्से को अपने-आप डीसीरियलाइज़ (अपने-आप) कर देता है और पुष्टि करने वाले टोकन की पुष्टि करता है.

Cloud Functions 2nd gen के लिए Firebase SDK टूल और उसके बाद के वर्शन, इन Firebase क्लाइंट के साथ इंटरऑपरेट करते हैं एचटीटीपीएस कॉल करने की सुविधा देने वाले फ़ंक्शन के साथ काम करने के लिए, SDK टूल के कम से कम वर्शन:

  • Apple प्लैटफ़ॉर्म के लिए Firebase SDK टूल 10.29.0
  • Android 21.0.0 के लिए Firebase SDK टूल
  • Firebase मॉड्यूलर वेब SDK टूल वर्शन 9.7.0

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

कॉल करने लायक फ़ंक्शन लिखें और डिप्लॉय करें

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 = request.data.text;
// Authentication / user information is automatically added to the request.
const uid = request.auth.uid;
const name = request.auth.token.name || null;
const picture = request.auth.token.picture || null;
const email = request.auth.token.email || null;

कॉल करने लायक फ़ंक्शन की जगह और जगह के बीच की दूरी कॉल करने वाले क्लाइंट की संख्या, नेटवर्क में देरी हो सकती है. परफ़ॉर्मेंस को ऑप्टिमाइज़ करने के लिए, उस फ़ंक्शन की जगह की जानकारी दें जहां साथ ही, कॉल करने की जगह की जानकारी को जगह की जानकारी के साथ अलाइन करें SDK टूल को इस्तेमाल करने के दौरान सेट किया जा सकता है आपको क्लाइंट-साइड पर रखना चाहिए.

इसके अलावा, आपके पास ऐप्लिकेशन की जांच से जुड़ा प्रमाणित करने वाला दस्तावेज़ अटैच करने का विकल्प होता है. इससे, गलत इस्तेमाल से जुड़े बैकएंड संसाधन. जैसे, बिलिंग से जुड़ी धोखाधड़ी या फ़िशिंग. यहां जाएं: Cloud Functions के लिए, ऐप्लिकेशन की जांच के लिए नीति उल्लंघन ठीक करने का तरीका (एनफ़ोर्समेंट) चालू करें.

नतीजा भेजा जा रहा है

क्लाइंट को डेटा वापस भेजने के लिए, ऐसा डेटा दें जिसे 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 message.

return getDatabase().ref("/messages").push({
  text: sanitizedMessage,
  author: {uid, name, picture, email},
}).then(() => {
  logger.info("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 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 (!request.auth) {
  // Throwing an HttpsError so that the client gets the error details.
  throw new HttpsError("failed-precondition", "The function must be " +
          "called while authenticated.");
}

कॉल करने लायक फ़ंक्शन को डिप्लॉय करें

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

firebase deploy --only functions:addMessage

अगर फ़ंक्शन डिप्लॉय करते समय अनुमतियों से जुड़ी गड़बड़ियां होती हैं, तो पक्का करें कि आईएएम की भूमिकाएं डिप्लॉयमेंट कमांड चलाने वाले उपयोगकर्ता को असाइन किया गया है.

अपना क्लाइंट डेवलपमेंट एनवायरमेंट सेट अप करना

यह पक्का करें कि आपने सभी ज़रूरी शर्तें पूरी की हैं. इसके बाद, ज़रूरी डिपेंडेंसी जोड़ें और क्लाइंट लाइब्रेरी पर लागू होती है.

iOS और उसके बाद के वर्शन

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

Firebase डिपेंडेंसी इंस्टॉल और मैनेज करने के लिए, Swift पैकेज मैनेजर का इस्तेमाल करें.

  1. Xcode में, अपना ऐप्लिकेशन प्रोजेक्ट खोलने के लिए, फ़ाइल > पैकेज जोड़ना.
  2. जब कहा जाए, तब Firebase Apple प्लैटफ़ॉर्म SDK टूल का रिपॉज़िटरी जोड़ें:
  3.   https://github.com/firebase/firebase-ios-sdk.git
  4. Cloud Functions लाइब्रेरी चुनें.
  5. अपने टारगेट की बिल्ड सेटिंग के अन्य लिंकर फ़्लैग सेक्शन में -ObjC फ़्लैग जोड़ें.
  6. यह काम पूरा होने पर, Xcode अपने-आप रिज़ॉल्व और डाउनलोड होना शुरू कर देगा पर निर्भर करता है.

Web

  1. दिए गए निर्देशों का पालन करके अपने वेब ऐप्लिकेशन में Firebase जोड़ें. दौड़ना पक्का करें अपने टर्मिनल से निम्न आदेश पाएं:
    npm install firebase@10.12.4 --save
    
  2. Firebase कोर और Cloud Functions, दोनों को मैन्युअल तरीके से ज़रूरी बनाएं:

     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

  1. दिए गए निर्देशों का पालन करके अपने वेब ऐप्लिकेशन में Firebase जोड़ें.
  2. Firebase कोर और Cloud Functions क्लाइंट लाइब्रेरी ऐप्लिकेशन:
    <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>
    

Cloud Functions SDK टूल, npm पैकेज के तौर पर भी उपलब्ध है.

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

Kotlin+KTX

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

  2. आपके मॉड्यूल (ऐप्लिकेशन-लेवल) की Gradle फ़ाइल में (आम तौर पर <project>/<app-module>/build.gradle.kts या <project>/<app-module>/build.gradle), Android के लिए Cloud Functions लाइब्रेरी के लिए डिपेंडेंसी जोड़ें. हमारा सुझाव है कि Firebase Android बीओएम लाइब्रेरी के वर्शन को कंट्रोल करने के लिए.

    dependencies {
        // Import the BoM for the Firebase platform
        implementation(platform("com.google.firebase:firebase-bom:33.1.2"))
    
        // 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 लाइब्रेरी का हर वर्शन बताना होगा इसकी डिपेंडेंसी लाइन में.

    ध्यान दें कि अगर आप अपने ऐप्लिकेशन में कई Firebase लाइब्रेरी का इस्तेमाल करते हैं, तो हम लाइब्रेरी वर्शन को मैनेज करने के लिए BoM का इस्तेमाल करने की सलाह देते हैं. इससे यह पक्का होता है कि साथ काम करता है.

    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:21.0.0")
    }
    
    क्या आपको Kotlin से जुड़े लाइब्रेरी मॉड्यूल की तलाश है? इतने समय में शुरू होगा अक्टूबर 2023 (Firebase BoM 32.5.0) में, Kotlin और Java डेवलपर, दोनों मुख्य लाइब्रेरी मॉड्यूल पर निर्भर करते हैं (जानकारी के लिए, इस पहल के बारे में अक्सर पूछे जाने वाले सवाल).

Java

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

  2. आपके मॉड्यूल (ऐप्लिकेशन-लेवल) की Gradle फ़ाइल में (आम तौर पर <project>/<app-module>/build.gradle.kts या <project>/<app-module>/build.gradle), Android के लिए Cloud Functions लाइब्रेरी के लिए डिपेंडेंसी जोड़ें. हमारा सुझाव है कि Firebase Android बीओएम लाइब्रेरी के वर्शन को कंट्रोल करने के लिए.

    dependencies {
        // Import the BoM for the Firebase platform
        implementation(platform("com.google.firebase:firebase-bom:33.1.2"))
    
        // 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 लाइब्रेरी का हर वर्शन बताना होगा इसकी डिपेंडेंसी लाइन में.

    ध्यान दें कि अगर आप अपने ऐप्लिकेशन में कई Firebase लाइब्रेरी का इस्तेमाल करते हैं, तो हम लाइब्रेरी वर्शन को मैनेज करने के लिए BoM का इस्तेमाल करने की सलाह देते हैं. इससे यह पक्का होता है कि साथ काम करता है.

    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:21.0.0")
    }
    
    क्या आपको Kotlin से जुड़े लाइब्रेरी मॉड्यूल की तलाश है? इतने समय में शुरू होगा अक्टूबर 2023 (Firebase BoM 32.5.0) में, Kotlin और Java डेवलपर, दोनों मुख्य लाइब्रेरी मॉड्यूल पर निर्भर करते हैं (जानकारी के लिए, इस पहल के बारे में अक्सर पूछे जाने वाले सवाल).

Dart

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

  2. अपने Flutter प्रोजेक्ट के रूट से, नीचे दी गई कमांड को चलाकर देखें प्लगिन इंस्टॉल करें:

    flutter pub add cloud_functions
    
  3. यह प्रोसेस पूरी होने के बाद, अपना Flutter ऐप्लिकेशन फिर से बनाएं:

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

    import 'package:cloud_functions/cloud_functions.dart';
    

C++

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

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

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

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

Unity

  1. दिए गए निर्देशों का पालन करके अपने Unity प्रोजेक्ट में Firebase जोड़ें.
  2. Firebase Unity SDK से FirebaseFunctions.unitypackage को आपका Unity प्रोजेक्ट भी सही है.

क्लाइंट SDK टूल शुरू करें

Cloud Functions का इंस्टेंस शुरू करें:

Swift

lazy var functions = Functions.functions()

Objective-C

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

Web

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

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;

C++

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

Unity

functions = Firebase.Functions.DefaultInstance;

फ़ंक्शन को कॉल करें

Swift

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
  }
}

Objective-C

[[_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

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

Web

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;

C++

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);
}

Unity

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. जानें कि कैसे काम किया जा सकता है कॉल किए जा सकने वाले फ़ंक्शन में गड़बड़ियों को ठीक करने के लिए किया जा सकता है.

Swift

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]
  }
  // ...
}

Objective-C

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

Web

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

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);
}

C++

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);
  // ...

Unity

 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;
  }
});

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