Forum Discussion
9 years ago
A guide to plugging into the Oculus API for player information
Hey;
My google-fu isn't coming up with a lot of information on how to pull from the Oculus API information about the player.
I'm specifically trying to figure out how to grab the user's Oculus name to put in as the handle in an online multiplayer, and maybe even grab their friends names as well.
Engine is Unity.
13 Replies
Replies have been turned off for this discussion
- benpadgetExplorerI'm assuming that you already have OculusPlatform.unitypackage installed in your project and have created an oculus store app and know its ID.
Go to the "Oculus Platform" drop down menu, click "Edit Settings". You'll then need to copy your app id to either the Oculus Rift App ID or Gear VR App ID field. Also - if you want to try this in the editor, you'll need to copy a user token into the Oculus User Token field under Unity Editor Settings. There should be a button to take you to the page on our developer site to create a user token. That will only be used when you run in the editor.
OK, READ THIS PART IF YOU DONT READ ANYTHING ELSE. Our GetLoggedInUser* calls are unique in that they are intended to work even if you don't have an internet connection. Because of this they get their data from the Oculus runtime. Long story short, this means they don't work in the Unity editor. So make sure run the code below in a standalone build or it won't return anything. We are improving this in the 1.6 version of the SDK.
First init the platform:
using Oculus.Platform;
using Oculus.Platform.Models;
Platform.Core.Initialize();
Here's how to get the logged in user and print their name:
Platform.Users.GetLoggedInUser().OnComplete((Message<User> msg) => {
if (msg.IsError) {
Debug.Log(msg.GetError().Message);
return;
}
Debug.Log("Your name is " + msg.Data.OculusID);
});
}
Here's how to get their friends:
Platform.Users.GetLoggedInUserFriends().OnComplete((Message<UserList> msg) => {
if (msg.IsError) {
LogError(msg.GetError());
return;
}
foreach(var friend in msg.Data) {
Debug.Log("Your friend's name is " + friend.OculusID);
}
}); - ProfessorTroyAdventurerDude - you're awesome! One thing - there seems to be an undocumented step to getting the platform initialized when targetting GearVR. The initialization always fails.
What's the missing thing for having a GearVR app working in the platform when deployed to the device?? - BinaryLegendProtege
Hey Ben,
benpadget said:
OK, READ THIS PART IF YOU DONT READ ANYTHING ELSE. Our GetLoggedInUser* calls are unique in that they are intended to work even if you don't have an internet connection. Because of this they get their data from the Oculus runtime. Long story short, this means they don't work in the Unity editor. So make sure run the code below in a standalone build or it won't return anything. We are improving this in the 1.6 version of the SDK.
I can't seem to get this to work on GearVR. i've followed your code exactly, and I'm also currently on the 1.6 Platform SDK, but I can't get the Oculus user when I go offline before starting my app. - ProfessorTroyAdventurerHey Binary -
That call for friends only returns friends who are online in the same game as you now. - BinaryLegendProtegeI'm aware of that, but I'm trying to get the current user, while in offline mode. We are primarily an online game, but want the ability to run our practice mode without internet connectivity.
- ProfessorTroyAdventurerSo if I understand correctly from your recent posts. You are able to initialize the core now, but the check to get your logged on user is failing when you run the application on your phone while the phone is offline?
- BinaryLegendProtegeThat is correct.
- BinaryLegendProtegeI've now got it to get the user's login when offline, even if restarting the phone without booting up the Oculus store app in between.
However, the callback Platform.Users.GetLoggedInUser().OnComplete((Message<User> msg) seems to take a long time to respond. I'd rather not leave the user in a black void before loading into our starting scene, but it seems that'll be the only way to ensure that our files load (the save system is based partially on OculusID). - BinaryLegendProtege@benpadget Continuing on data we want, is there a way to get the user's profile image? We would like to display it in a spectator view that we've made.
- ProfessorTroyAdventurer@BinaryLegend
The documentation for the SDK is online. https://developer.oculus.com/documentation/platform/latest/sdk-reference/model-user/ is likely the structure you're looking for.
Cheers!
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device