User Profile API

The VIVEPORT SDK provides a way to have information about the user.

How to use User Profile API

Note

Remember that you should call Top Level API - Api.Init() and Stats & Achievements API - UserStats.IsReady() to setup the SDK library and client runtime before you call user profile APIs. And please remember to call Top Level API - Api.Shutdown() to teardown the library runtime after you finish using VIVEPORT SDK.

Accessing and modifying the data from within the content is easy:

  1. You can call GetUserId() to get the end user’s public ID.

  2. You can call GetUserName() to get the end user’s display name. The end user can set up his display name under the user information page. The display name rule is showing the end user display name first. If the end user doesn’t set up the display name, the system will get the first name instead.

    _images/DisplayName.png
  3. You can call GetUserAvatarUrl() to get an url link to end user’s avatar.

Note

The return string format from GetUserId() is ASCII, and the one from GetUserName() is UTF-8.

Important

Please see the Error Codes and Trouble Shooting pages to know what to do when you got problems using the VIVEPORT SDK.

Detailed Example in Unity

using UnityEngine;
using System;
using Viveport;

/** Language: C# */
public class ViveportDemo : MonoBehaviour
{
   static string VIVEPORT_ID = "bd67b286-aafc-449d-8896-bb7e9b351876";

   // Use this for initialization
   void Start ()
   {
       Api.Init(InitStatusHandler, VIVEPORT_ID);
   }

   private static void InitStatusHandler(int nResult)
   {
       Viveport.Core.Logger.Log("Init(): " + nResult);
       if (nResult != 0)
       {
          Viveport.Core.Logger.Log("Init setup error ...");
          // Handle error
       }
       UserStats.IsReady(IsReadyHandler);
   }

   private static void IsReadyHandler(int nResult)
   {
       if (nResult != 0)
       {
          Viveport.Core.Logger.Log("Platform setup error ...");
          // Handle error
       }
       Viveport.Core.Logger.Log("UserId: " + User.GetUserId());
       Viveport.Core.Logger.Log("userName: " + User.GetUserName());
       Viveport.Core.Logger.Log("userAvatarUrl: " + User.GetUserAvatarUrl());
       // Do more things
   }
}

Detailed Example in Unreal

ViveportUserDemo.h

#include "Components/ActorComponent.h"
#include "ViveportApi.h"
#include "ViveportUser.h"
#include "ViveportType.h"

#include "ViveportUserDemo.generated.h"

UCLASS(ClassGroup = (Viveport), meta = (BlueprintSpawnableComponent))
class VIVEPORTSDK_API UViveportUserDemo : public UActorComponent
{
    GENERATED_BODY()

public:
    // Sets default values for this component's properties
    UViveportUserDemo();

    // Called when the game starts
    void BeginPlay() override;

    // Called every frame
    void TickComponent(
        float DeltaTime,
        ELevelTick TickType,
        FActorComponentTickFunction* ThisTickFunction
        ) override;
};

ViveportUserDemo.cpp

#include "ViveportSDKPrivatePCH.h"
#include "ViveportUserDemo.h"

// Sets default values for this component's properties
UViveportUserDemo::UViveportUserDemo()
{
    // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
    // off to improve performance if you don't need them.
    bWantsBeginPlay = true;
    PrimaryComponentTick.bCanEverTick = true;
}

// Called when the game starts
void UViveportUserDemo::BeginPlay()
{
    Super::BeginPlay();

    const FString fstring = FString::Printf(TEXT("GetUserID=%s\nGetUserName=%s\nGetUserAvatarUrl=%s"),
                                            *UViveportUser::GetUserID(),
                                            *UViveportUser::GetUserName(),
                                            *UViveportUser::GetUserAvatarUrl());
    GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::White, fstring);
}

// Called every frame
void UViveportUserDemo::TickComponent(float DeltaTime,
                                      ELevelTick TickType,
                                      FActorComponentTickFunction* ThisTickFunction)
{
    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}