How to get user's avatar profile picture — Oculus
Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

How to get user's avatar profile picture

Hello!

I've managed to obtain the user profile picture url with a S2S REST request following this thread. Is there a similar way to get the user's avatar profile picture? (I'm refering to the avatar picture that appears in the user profile)

Thanks in advance!


Comments

  • myBadStudiosmyBadStudios Posts: 20
    Brain Burst
    Here's how I do it in Unity...


           Texture2D player_avatar;   
           void Start()
            {
                    if ( XRSettings.loadedDeviceName == "Oculus" )
                    {
                        Core.AsyncInitialize();
                        Entitlements.IsUserEntitledToApplication().OnComplete( EntitlementCallback );
                    }
            }
    
            void EntitlementCallback( Message msg )
            {
                if ( msg.IsError )
                {
                    Debug.LogError( "You are NOT entitled to use this app." );
                    UnityEngine.Application.Quit();
                }
                else
                {
                    Users.GetLoggedInUser().OnComplete( GetLoggedInUserCallback );
                    Request.RunCallbacks();
                }
            }
    
            async void GetLoggedInUserCallback( Message message )
            {
                    Avatar = Instantiate( Resources.Load("MyCustomPrefab"));
                    Avatar.StartWithControllers = true;
                    Avatar.oculusUserID = message.Data.ID.ToString();
                player_avatar = await FetchPlayerImage( message.Data.ImageURL );
            }
    
            async Task FetchPlayerImage( string url )
            {
                url = url.Trim();
                if ( !string.IsNullOrEmpty( url ) )
                {
                    WWW w = new WWW( url );
                    while ( !w.isDone )
                        await Task.Delay( 100 );
                    if ( string.IsNullOrEmpty( w.error ) )
                        return w.texture;
                    else
                        Debug.LogWarning( w.error );
                }
                return null;
            }
    
  • RocketQueenRocketQueen Posts: 4
    NerveGear
    Hi,

    I'll forward this to our platform SDK team and see if they can offer guidance on whether this is exposed behavior or road-mapped for the future.

    EDIT:

    You can currently retrieve a user's avatar profile picture URI using this:

    https://graph.oculus.com/<userID>?access_token=<token>&fields=avatar_v2{avatar_image{uri}}

    and by using the below if you are still using older (deprecated) avatars:

    avatar{avatar_image{uri}}

    This worked for me! Thank you so much :)
Sign In or Register to comment.