question

nigolu7 avatar image
nigolu7 asked

How to get other's data object

1 comment
10 |1200

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

nigolu7 avatar image nigolu7 commented ·

I'm trying to retrieve a data object with the player title ID, but the log says not authorized

0 Likes 0 ·

1 Answer

·
Xiao Zha avatar image
Xiao Zha answered

Since players only have their own EntityToken at the title_player_account level on the client side, calling GetObjects API on the client side will only return the caller's own data object. But you can call GetObjects API in Clould Script for Cloud Script holds a title-level entity token, which has the permission to get any entity objects. And, since the GetObjects API is an Entity API , you can call the GetObjects API with “entity” global variable defined in the CloudScript , you can find the entity corresponding code snippet in the Cloud Script default version. When you want to call this cloudscript method on the client side, you need to call ExcuteCloudScript.

In addition to calling CloudScript methods you can also modify the global entity policy in title settings->API feature to allow the client to get other player’s object directly. The code is as follows:

{
    "Action": "Read",
    "Effect": "Allow",
    "Resource": "pfrn:data--*!*/Profile/Objects/*",
    "Principal":"*",
    "Comment": "Allow objects profile access",
    "Condition":null
  }
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.

nigolu7 avatar image nigolu7 commented ·

Do you have any examples of C# codes?

0 Likes 0 ·
Xiao Zha avatar image Xiao Zha nigolu7 commented ·

The code in Cloud Script:

handlers.GetOtherDataObject=function(args,context)
{
    var result=entity.GetObjects({
        "Entity": {
                    "Id": args.id,
                    "Type": "title_player_account",
                    "TypeString": "title_player_account",}
                });
    return result.Objects;
}

The C# code example to call this function:

    public void Test(string ID)
    {
        PlayFabClientAPI.ExecuteCloudScript(
            new ExecuteCloudScriptRequest 
            { 
                FunctionName = "GetOtherDataObject", 
                FunctionParameter = new Dictionary<string,string>{ { "id", ID } }, 
            },
            result => { Debug.Log(result.FunctionResult); },
            error => { Debug.Log("failure!"); }
            );
    }
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.