【发布时间】:2017-06-07 07:05:12
【问题描述】:
我不明白如何在存储中传递身份验证值... 以下是尝试写入文件时返回的错误,位于代码本身下方。 有人遇到过这样的问题吗?
权限规则使用标准
service firebase.storage {
match /b/project.appspot.com/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
System.AggregateException:类型异常 'System.AggregateException' 被抛出。 ----------------- Firebase.Storage.StorageException:用户无权访问此对象。 ---> System.IO.IOException: 的 服务器已终止上传会话 --- 内部异常结束 堆栈跟踪---
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase;
using Firebase.Storage;
using Firebase.Auth;
public class Storage : MonoBehaviour {
public Texture2D texture;
public Auth autentification;
FirebaseApp app;
AppOptions options;
FirebaseStorage storage;
StorageReference storage_ref, ref_file;
// Use this for initialization
void Start () {
InitFirebase ();
}
public void InitFirebase(){
print("InitFirebase start");
DependencyStatus dependencyStatus = FirebaseApp.CheckDependencies();
if (dependencyStatus != DependencyStatus.Available) {
FirebaseApp.FixDependenciesAsync().ContinueWith(task => {
dependencyStatus = FirebaseApp.CheckDependencies();
if (dependencyStatus == DependencyStatus.Available) {
Signin();
} else {
print("Could not resolve all dependencies: " + dependencyStatus);
}
});
} else {
Signin();
}
}
public void Signin(){
print("Signin start");
string _testEmail = "test@gmail.com";
string _testPassword = "qwerty";
options = new AppOptions ();
options.ApiKey = "API_KEY";
options.StorageBucket = "STORAGE_BUCKET";
options.AppId = "APPID";
app = FirebaseApp.Create (options, "name");
FirebaseAuth.GetAuth(app).SignInWithEmailAndPasswordAsync (_testEmail, _testPassword).ContinueWith ((System.Threading.Tasks.Task<FirebaseUser> authTask) => {
if (authTask.IsCanceled) {
print("signin canceled");
} else if (authTask.IsFaulted) {
print("signin faulted " + authTask.Exception.ToString());
} else if (authTask.IsCompleted) {
print("signin complete , user id is " + authTask.Result.UserId);
storage = FirebaseStorage.GetInstance(app);
storage_ref = storage.GetReferenceFromUrl("gs://testproject-3b976.appspot.com/data/");
Upload ("images/" + texture.name + ".png");
} else {
print("signin unknown error");
}
});
}
【问题讨论】:
标签: unity3d firebase firebase-authentication firebase-storage