question

Philip Alexander Prates Machado avatar image
Philip Alexander Prates Machado asked

"SetDeveloperSecretKey" in c++

I have been trying to set the developer secret key in c++ so i can call "UpdatePlayerStatistics" after, unfortunately google doesnt even return results for c# so i am a bit lost.

I arrived at the following functions which i dont even know if they are the right ones to call or not...

PlayFab::PlayFabSettings::SetDeveloperSecretKey(FString("keyhere"));
	
IPlayFab::Get().setApiSecretKey("keyhere");

First one throws a linker error and the second one runs BUT when you try to run the function it still gives an error and asks for the secret key.

This needs to be called in the server so that the server can update the players MMR after the match is over.

So if any one could tell me the right function to call along with the nescessary includes it would be much appreciated.

apisunreal
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Here is the code of an Actor I created that sets the Secret Key, TitleId and makes a server API call, for your reference:

LoginActor.cpp:

#include "LoginActor.h"
#include "Core/PlayFabServerAPI.h"
#include "PlayFabCommon.h"
ALoginActor::ALoginActor()
{
	PrimaryActorTick.bCanEverTick = true;
}


void ALoginActor::BeginPlay()
{
	Super::BeginPlay();
	IPlayFabCommonModuleInterface::Get().SetTitleId(FString("xxx"));
	IPlayFabCommonModuleInterface::Get().SetDeveloperSecretKey(FString("xxx"));


	serverAPI = IPlayFabModuleInterface::Get().GetServerAPI();
	PlayFab::ServerModels::FGetPlayerProfileRequest request;


	request.PlayFabId = "xxx";


	serverAPI->GetPlayerProfile(request,
		PlayFab::UPlayFabServerAPI::FGetPlayerProfileDelegate::CreateUObject(this, &ALoginActor::OnSuccess),
		PlayFab::FPlayFabErrorDelegate::CreateUObject(this, &ALoginActor::OnError)
	);


}




void ALoginActor::OnSuccess(const PlayFab::ServerModels::FGetPlayerProfileResult& Result) const
{
	UE_LOG(LogTemp, Log, TEXT("Get Player Profile success"));




}


void ALoginActor::OnError(const PlayFab::FPlayFabCppError& ErrorResult) const
{
	UE_LOG(LogTemp, Error, TEXT("Something went wrong with your first API call.\nHere's some debug information:\n%s"), *ErrorResult.GenerateErrorReport());
}


void ALoginActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

LoginActor.h:

#pragma once


#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "PlayFab.h"
#include "Core/PlayFabError.h"
#include "Core/PlayFabServerDataModels.h"
#include "LoginActor.generated.h"


UCLASS()
class ALoginActor : public AActor
{
	GENERATED_BODY()
public:
	ALoginActor();
	virtual void BeginPlay() override;
	void OnSuccess(const PlayFab::ServerModels::FGetPlayerProfileResult& Result) const;
	void OnError(const PlayFab::FPlayFabCppError& Result) const;


	virtual void Tick(float DeltaSeconds) override;
private:
	PlayFabServerPtr serverAPI = nullptr;
};
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image Citrus Yan commented ·

You can also set the secretkey in Project Settings -> PlayFab:

0 Likes 0 ·
1.png (45.0 KiB)
Philip Alexander Prates Machado avatar image Philip Alexander Prates Machado commented ·

    This is exactly what i needed, to be more specific just this 2 lines.

    #include"PlayFabCommon.h"

    IPlayFabCommonModuleInterface::Get().SetDeveloperSecretKey(FString("xxx"));

    Thank you very much!

    0 Likes 0 ·

    Write an Answer

    Hint: Notify or tag a user in this post by typing @username.

    Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.