Forum Discussion

Sananisgood's avatar
Sananisgood
Honored Guest
11 days ago

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

1 Reply

  • Hey Sananisgood!

    Thanks for reaching out. I understand you're having trouble with the Platform SDK. Would you mind letting me know how you installed your app? As in, is it installed from the Meta Quest store via the release channel or is it sideloaded? It's possible that if it's sideloaded that is the reason for the fail. If the installation isn't the problem, could you please run "adb logcat -s Unity" and send over the output?

    Let me know if any of that was helpful, and if not I'll await your logs!

    -G

β†’ Find helpful resources to begin your development journey in Getting Started

β†’ Get the latest information about HorizonOS development in News & Announcements.

β†’ Access Start program mentor videos and share knowledge, tutorials, and videos in Community Resources.

β†’ Get support or provide help in Questions & Discussions.

β†’ Show off your work in What I’m Building to get feedback and find playtesters.

β†’ Looking for documentation?  Developer Docs

β†’ Looking for account support?  Support Center

β†’ Looking for the previous forum?  Forum Archive

β†’ Looking to join the Start program? Apply here.

 

Recent Discussions