question

Kamil avatar image
Kamil asked

Groups: Create a group from Unity project - not allowed to complete operation.

Hello,

I'm trying to create a group on Playfab from my Unity project. First, I logged in as Playfab user and in Awake method getting my playerID (title) with code below:

PlayFabClientAPI.GetPlayerCombinedInfo(new PlayFab.ClientModels.GetPlayerCombinedInfoRequest
            {
                InfoRequestParameters = new PlayFab.ClientModels.GetPlayerCombinedInfoRequestParams
                {
                    GetUserAccountInfo = true
                }
            },
                result => { playerPlayfabID = result.InfoResultPayload.AccountInfo.TitleInfo.TitlePlayerAccount.Id; Debug.Log("playfabId " + playerPlayfabID); },
                fail => { Debug.Log(fail.GenerateErrorReport()); });

Next, I created input field for group name and attached some method to button on scene with that code (I added EntityType parameter to EntityKeyMaker method because otherwise I got error (unkown Type or TypeString):

CreateGroup(createGroupInput.text, EntityKeyMaker(playerPlayfabID, "title_player_account"));

After executing the above code, I get a message in the console:

/Group/CreateGroup: The requesting entity is not allowed to complete this operation because the target entity is not a child of the requesting entity.
UnityEngine.Debug:LogError (object)
TestGuildController.GuildTestController:OnSharedError (PlayFab.PlayFabError) (at Assets/Scripts/_Test_Kamil/GuildTestController.cs:51)
PlayFab.Internal.PlayFabUnityHttp:OnResponse (string,PlayFab.Internal.CallRequestContainer) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:214)
PlayFab.Internal.PlayFabUnityHttp/<Post>d__12:MoveNext () (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:153)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

How I can solve my problem? May I forgot about something?

unity3d
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

·
Sarah Zhang avatar image
Sarah Zhang answered

For clarification, the PlayFabId is not the EntityID of the entity title_player_account, instead of it, it’s the EntityID of the entity master_player_account. In your case, you can only use the entity title_player_account and title to access the API CreateGroup, and if you want to provide the Entity in the request body, you need to provide the correct EntityIDs of them. Besides, the player’s title_player_account entity object including the Id and the type is a part of the PlayFab login API’s response. So, in Unity project, you can cache the Entity object returned by the login method directly instead of calling the API GetPlayerCombinedInfo to get it. Finally, in fact, you can omit the Entity field when calling CreateGroup. If you don't provide the entity object, by default, the API will recognize the owner of the EntityToken as the creator. The code could be something like this.

public class GroupManager : MonoBehaviour
{
    public PlayFab.ClientModels.EntityKey CurrentEntity { get; private set; }
    void Start()
    {
        PlayFabClientAPI.LoginWithCustomID(
            new PlayFab.ClientModels.LoginWithCustomIDRequest()
            {
                CustomId = "xxxxx",
                CreateAccount = true,
                TitleId = "xxxxx"
            },
            OnSuccess,
            OnFail);
    }
    private void OnSuccess(LoginResult result)
    {
        CurrentEntity = result.EntityToken.Entity;
        PlayFabGroupsAPI.CreateGroup(
            new PlayFab.GroupsModels.CreateGroupRequest()
            {
                GroupName = "xxxxxx",
                //The Entity field can be omitted.
                //Entity = new PlayFab.GroupsModels.EntityKey { Id = CurrentEntity.Id, Type = CurrentEntity.Type }


            },
            OnCreateGroupSuccess,
            OnFail);
    }    private void OnCreateGroupSuccess(CreateGroupResponse result)
    {
        Debug.Log(result.Group.Id);
    }
    private void OnFail(PlayFabError error)
    {
        Debug.Log(error.GenerateErrorReport());
    }

}
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.

Kamil avatar image Kamil commented ·
Thank for your answer.Your code works perfectly. Unfortunately, I can't omit Entity field, otherwise group is associated to random user, not to logged user (I checked this on Playfab dashboard).
0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Kamil commented ·

Glad to hear the question was solved.

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.