Download

New to C++ In Unreal Engine & want a quick tip in OnlineSubsystem

I am currently developing my game in Blueprints. But I need to get a variable that I didn’t find in it but in C++.

In OnlineSubsytem using android deivces (or maybe in IOS later on) I want to get the access token so I can connect with GameSparks.com by OAuth 2.0

I wrote this code in Blueprint Function Library:


FString UCToBluePrintFunctionsLibrary::getPlayerToken()
{

    IOnlineSubsystem* ion = IOnlineSubsystem::Get();
    IOnlineIdentityPtr OnlineIdentity = ion->GetIdentityInterface();
    if (OnlineIdentity.IsValid())
    { 
        return OnlineIdentity->GetAuthToken(0);

    }
    return FString("None");
}


in my blueprints I made a login button with the blueprint ShowExternalLoginUI, It give me success in android, then I made another button to fire the event above of getPlayerToken, before I login it give me none, and after login it gives me NotAcquired. !!!

After that I noticed when writing GetAuthToken , it written @Todo - remove and use getUserAccount instead, and also have a method inside it getAccessToken.

Because I am new to C++ I can’t make the write syntax to get the access token so I can pass it to gamesparks and connect.

If anyone can help I will Appreciate it.

I made this code but it gives me an error:


FString UCToBluePrintFunctionsLibrary::getUserAccount()
{
    IOnlineSubsystem* ion = IOnlineSubsystem::Get();
    TSharedPtr<const FUniqueNetId> pid = ion->GetIdentityInterface()->GetUniquePlayerId(0);

    IOnlineIdentityPtr OnlineIdentity = ion->GetIdentityInterface();
    if (pid.IsValid()) {
        TSharedPtr<const FUserOnlineAccount> userAccount = OnlineIdentity->GetUserAccount(pid);
        return userAccount.GetAccessToken();

    }

    return FString();
}


It says: no suitable user-defined conversion from “TSharedPtr<const FUniqueNetId, ESPMode::NotThreadSafe>” to “const FUniqueNetId” exists

can someone correct me plz?