我正在使用 Firebase API for Unity,我正在使用 Post 請求將一些資料推送到實時資料庫 在使用該 Post 請求之后,我需要為新節點創建的 ID 來執行其他操作,但我不確定如何檢索該 ID .
Firebase.Instance.Post(uri, new Dictionary<string, string>() { { "name", name } },
delegate { Debug.Log("Name has been added successfully!"); //here is where i need the new ID to do something else },
delegate { Debug.Log("Something Wrong! .. Please try again later"); });
帖子功能:
public void Post<T, K>(URI uri, T body, System.Action<K> onSuccess, System.Action<string> onFail)
{
RequestHelper currentRequest = new RequestHelper
{
Uri = uri.Path,
BodyString = JsonConvert.SerializeObject(body),
IgnoreHttpException = true
};
Debug.Log("BODY_post: " currentRequest.BodyString);
RestClient.Post(currentRequest, (exception, res) => ResolveResponse(exception, res, onSuccess, onFail));
}
void ResolveResponse<T>(RequestException exception, ResponseHelper res, System.Action<T> onSuccess, System.Action<string> onFail)
{
string returnedText = res.Text;
AuthError authError = null;
try
{
authError = JsonConvert.DeserializeObject<AuthError>(returnedText);
}
catch (System.Exception ex)
{
Debug.Log(ex);
}
finally
{
if (authError != null && authError.error != null && authError.error.message != null)
{
onFail(BeautifyMessage(authError.error.message));
}
else if (exception != null && (exception.IsHttpError || exception.IsNetworkError))
{
onFail(BeautifyMessage(exception.Message));
}
else if (typeof(T) == typeof(string))
{
onSuccess((T)(object)returnedText);
}
else
{
onSuccess(JsonConvert.DeserializeObject<T>(returnedText));
}
}
}
它呼叫了其余 api 的庫 post 函式。
uj5u.com熱心網友回復:
您正在包裝 Firebase REST API,其中呼叫POST回傳回應中的密鑰:
成功的請求由 200 OK HTTP 狀態代碼指示。回應包含 POST 請求中指定的新資料的子名稱。
{ "name": "-INOQPH-aV_psbk3ZXEX" }
因此,您的回應處理程式將需要決議該結果,并將"-IN...."密鑰回傳給呼叫者。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/411863.html
標籤:
下一篇:如何使用輸入欄位使變數作業?
