Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Getting Oculus Id, displayname, imageurl

Discussion in 'VR' started by JD_FVTC, Jun 8, 2021.

  1. JD_FVTC

    JD_FVTC

    Joined:
    Oct 20, 2017
    Posts:
    54
    I'm attempting to get the data about the user logged into the oculus quest headset.
    I'm attempting to retrieve it after the entitlement is established.

    I'm testing the install on the device not connected via link cable.

    I think my error is on line
    var whatever = Oculus.Platform.Users.GetLoggedInUser();
    I had to add Oculus instead of
    Platform.Users.GetLoggedInUser();

    This is based off oculus documentation here
    https://developer.oculus.com/documentation/unity/ps-presence/

    What am I missing?

    Code (CSharp):
    1. public class AppEntitlementCheck : MonoBehaviour
    2. {
    3.     public TextMeshProUGUI feedback;
    4.     void Awake()
    5.     {
    6.         try
    7.         {
    8.             Core.AsyncInitialize();
    9.             Entitlements.IsUserEntitledToApplication().OnComplete(EntitlementCallback);
    10.         }
    11.         catch (UnityException e)
    12.         {
    13.             Debug.LogError("Platform failed to initialize due to exception.");
    14.             Debug.LogException(e);
    15.             // Immediately quit the application.
    16.             UnityEngine.Application.Quit();
    17.         }
    18.     }
    19.  
    20.  
    21.     // Called when the Oculus Platform completes the async entitlement check request and a result is available.
    22.     void EntitlementCallback(Message msg)
    23.     {
    24.         if (msg.IsError) // User failed entitlement check
    25.         {
    26.             // Implements a default behavior for an entitlement check failure -- log the failure and exit the app.
    27.             Debug.LogError("You are NOT entitled to use this app.");
    28.             UnityEngine.Application.Quit();
    29.         }
    30.         else // User passed entitlement check
    31.         {
    32.             // Log the succeeded entitlement check for debugging.
    33.             Debug.Log("You are entitled to use this app.");
    34.         }
    35.         GetUserData();
    36.     }
    37.     void GetUserData()
    38.     {
    39.        var whatever = Oculus.Platform.Users.GetLoggedInUser();
    40.         feedback.text = "hmm " + whatever.RequestID.ToString();
    41.         whatever.OnComplete(dothis);
    42.     }
    43.  
    44.     private void dothis(Message<User> message)
    45.     {
    46.         var thismesg = message;
    47.         var user = thismesg.GetUser();
    48.         feedback.text += "\n userid:="+ user.OculusID.ToString();
    49.         feedback.text += "\n id:=" + user.ID;
    50.         feedback.text += "\n ImageURL:=" + user.ImageURL;
    51.         feedback.text += "\n DisplayName:=" + user.DisplayName;
    52.         feedback.text += "\n InviteToken:=" + user.InviteToken;
    53.         feedback.text += "\n PresenceDestinationApiName:=" + user.PresenceDestinationApiName;
    54.      
    55.     }
    56. }