Forum Discussion

Piflyon's avatar
Piflyon
Explorer
9 years ago

How to get FRIENDS names or IDs (Unity, plateform SDK on PC, C#) ? GetLoggedInUserFriends()

Hi,
(I'm french, please excuse my english. I Hope I'm in the right place, as google did not help me, and this forum search function does not allow to filter developper's forum only.)

I am already displaying highscores in a custom online leaderboard (name, score, level reached, etc...). in which I highlight the current player score.

I would like to also highlight user's friends scores. How to get these informations ?

What would be perfect is an either a string Array of friends' names (OculusID I think).

The documentation is totally useless about GetLoggedInUserFriends():
https://developer3.oculus.com/documentation/platform/latest/concepts/dg-presence/

So far, here is how I get user's name  (took me hours to make it work, as there is no working example anywhere)(anywhere else but here now  ;) ) :
===== code ====
void OculusAppelStore() {
Oculus.Platform.Core.Initialize ();
Oculus.Platform.Entitlements.IsUserEntitledToApplication ().OnComplete (OculusVerifDroits);
}
void OculusVerifDroits(Message _msg){
if (!_msg.IsError) {
Debug.Log ("Ok ");
Users.GetLoggedInUser ().OnComplete (OculusLoggedInUser);
} else {
Debug.Log ("Nope " + _msg);
}
}
void OculusLoggedInUser(Message _msg) {
if (!_msg.IsError) {
User u = _msg.GetUser ();
playerName = u.OculusID;
} else {
Debug.Log ("erreur loggedIn");
}
}
===== /code=====
I say it again : it's a custom online leaderboard, I don't use the Oculus'one (too complicated for my developper skills).

Thank you for your help.
Cédric.

5 Replies

  • juanoldinho's avatar
    juanoldinho
    Heroic Explorer
    Hi,

    Using PlatformManager.cs there are static variables for a user id and username.
    PlatformManager.MyID  //returns the Oculus ID of the logged in user
    PlatformManager.MyOculusID //returns the Oculus username of the logged in user

    You can also perform your own API call

    Users.GetLoggedInUser ().OnComplete ((Message<User> msg) => {
    Debug.Log("User ID: " + msg.Data.ID);
    Debug.Log("Oculus ID: " + msg.Data.OculusID);
    });

    You should be able to do a similar call for the Logged in Users Friends

    Users.GetLoggedInUserFriends ().OnComplete ((Message<UserList> msg) => {
    foreach (var friend in msg.Data){
    Debug.Log("friend: " + friend);
    }
    });


  • Hi Juanoldinho,

    Sorry, but nothing works. I'm using Unity and C#. I also use :

    using Oculus.Platform;
    using Oculus.Platform.Models;

    The problems in your answer :

    PlatformManager does not exist,
    msg.Data does not exist. (no definition for "Data").

    Can you complete your help ?
    Thank you.

    Cédric.
  • juanoldinho's avatar
    juanoldinho
    Heroic Explorer
    Hi

    Apologies, PlatformManager was my own implementation, so you can disregard the first two lines above. 

    The other API calls should function as expected. 
  • Hi, 

    (in the last part of your code, the last foreach).

    Finally I got it work with :
    Debug.Log (friend.OculusID)
    and not "friend" only.
    Thank You Juanoldinho.

    Cédric.