I cant get the meta username usingplatform sdk. can you help?
I am unable to get the username for my game in unity. ihave sdkplatform and core installed. yet it either doesntwork or silently fails. cansomeone help?. ive waited 6 hours for propogation yet its not working.
using Oculus.Platform;
using Oculus.Platform.Models;
using UnityEngine;
using System;
public class MetaUserID : MonoBehaviour
{
public static MetaUserID Instance;
public static event Action<string> OnUserReady;
[Header("Meta App ID")]
[SerializeField] private string metaAppId = "26049850781267112";
private bool initialized = false;
void Awake()
{
if (Instance != null)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
Debug.Log("π₯ MetaUserID Awake");
InitPlatform();
}
void Update()
{
// π΄ REQUIRED for Oculus Platform SDK
Request.RunCallbacks();
}
void InitPlatform()
{
try
{
Core.AsyncInitialize(metaAppId).OnComplete(OnPlatformInitialized);
}
catch (Exception e)
{
Debug.LogError("β Core init exception: " + e);
}
}
void OnPlatformInitialized(Message msg)
{
if (msg.IsError)
{
Debug.LogError("β Meta Platform init failed");
Debug.LogError(msg.GetError().Message);
return;
}
Debug.Log("β Meta Platform initialized");
Entitlements.IsUserEntitledToApplication()
.OnComplete(OnEntitlementChecked);
}
void OnEntitlementChecked(Message msg)
{
if (msg.IsError)
{
Debug.LogError("β NOT ENTITLED");
Debug.LogError(msg.GetError().Message);
return;
}
Debug.Log("β User entitled");
Users.GetLoggedInUser().OnComplete(OnUserReceived);
}
void OnUserReceived(Message<User> message)
{
if (message.IsError)
{
Debug.LogError("β Failed to get Meta user");
Debug.LogError(message.GetError().Message);
return;
}
string metaId = message.Data.ID.ToString();
Debug.Log("β
Meta User ID: " + metaId);
Debug.Log("π€ Oculus Username: " + message.Data.OculusID);
OnUserReady?.Invoke(metaId);
}
}
using Firebase;
using Firebase.Auth;
using Firebase.Database;
using Firebase.Extensions;
using UnityEngine;
public class DataBaseManager : MonoBehaviour
{
public static DataBaseManager Instance;
DatabaseReference db;
bool firebaseReady = false;
bool uploaded = false;
string metaUserId = null;
void Awake()
{
if (Instance != null)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
}
void Start()
{
MetaUserID.OnUserReady += OnMetaUserReady;
InitFirebase();
}
void OnDestroy()
{
MetaUserID.OnUserReady -= OnMetaUserReady;
}
void InitFirebase()
{
FirebaseApp.CheckAndFixDependenciesAsync()
.ContinueWithOnMainThread(task =>
{
if (task.Result != DependencyStatus.Available)
{
Debug.LogError("Deps failed: " + task.Result);
return;
}
FirebaseApp app = FirebaseApp.DefaultInstance;
app.Options.DatabaseUrl =
new System.Uri("https://kargil-98ca1-default-rtdb.firebaseio.com/");
db = FirebaseDatabase.GetInstance(app).RootReference;
firebaseReady = true;
TryUpload();
});
}
void OnMetaUserReady(string id)
{
metaUserId = id;
TryUpload();
}
void TryUpload()
{
if (!firebaseReady) return;
if (string.IsNullOrEmpty(metaUserId)) return;
if (uploaded) return;
uploaded = true;
Debug.Log("π Uploading XP for " + metaUserId);
db.Child("users")
.Child(metaUserId)
.Child("xp")
.SetValueAsync(100)
.ContinueWithOnMainThread(task =>
{
if (task.IsFaulted)
Debug.LogError("β XP upload failed: " + task.Exception);
else
Debug.Log("β
XP uploaded");
});
}
}