【问题标题】:Response is not a valid JSON object using StreamChat in cloud functions响应不是在云函数中使用 StreamChat 的有效 JSON 对象
【发布时间】:2022-07-07 15:14:22
【问题描述】:

以下是我得到的错误。我看了一个教程,开发人员有完全相同的代码,它在他的最后工作,我不知道我做错了什么。我通过stream_chat_flutter_core包使用getstream.io平台。

Response is not valid JSON object.
I/flutter ( 8805): 
I/flutter ( 8805): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
I/flutter ( 8805): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)
I/flutter ( 8805): <asynchronous suspension>
I/flutter ( 8805): #2      MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:23:24)
I/flutter ( 8805): <asynchronous suspension>
I/flutter ( 8805): #3      HttpsCallable.call (package:cloud_functions/src/https_callable.dart:49:37)
I/flutter ( 8805): <asynchronous suspension>
I/flutter ( 8805): #4      FirebaseService.joinWithEmailAndPassword (package:thrills/util/firebase_service.dart:357:25)
I/flutter ( 8805): <asynchronous suspension>
I/flutter ( 8805): #5      _JoinState.build.<anonymous closure> (package:thrills/screens/join/join.dart:285:33)
I/flutter ( 8805): <asynchronous suspension>

下面是我在firebase中使用的云功能

const StreamChat = require('stream-chat').StreamChat;
const functions = require("firebase-functions");
const admin = require("firebase-admin");

admin.initializeApp();

const serverClient = StreamChat.getInstance(functions.config().stream.key, functions.config().stream.secret);

exports.createStreamUserAndGetToken = functions.region("us-west2").https.onCall(async (data, context) => {
  // 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.');
  } else {
    try {
      // Create user using the serverClient.
      await serverClient.upsertUser({
        id: context.auth.uid,
        name: context.auth.token.name,
        email: context.auth.token.email,
        image: context.auth.token.image,
      });

      // Create and return user auth token.
      return serverClient.createToken(context.auth.uid);
    } catch (err) {
      console.error(`Unable to create user with ID ${context.auth.uid} on Stream. Error ${err}`);
      // Throwing an HttpsError so that the client gets the error details.
      throw new functions.https.HttpsError('aborted', "Could not create Stream user");
    }
  }
});

最后,这是我调用函数和检索数据的方式

final callable = FirebaseFunctions.instance
            .httpsCallable('createStreamUserAndGetToken');
final results = await callable();
some random code... (results.data is only used once as an argument to some function)
results.data as String       

【问题讨论】:

    标签: javascript json firebase google-cloud-functions getstream-io


    【解决方案1】:

    我想您正在观看流媒体开发者的视频。请问您是否解决了这个问题,因为我目前也面临这个问题?

    【讨论】:

      猜你喜欢
      • 2021-01-21
      • 2020-07-26
      • 2021-06-24
      • 1970-01-01
      • 2021-03-03
      • 2019-08-25
      • 2020-08-17
      • 2022-06-11
      • 2023-03-18
      相关资源
      最近更新 更多