question

Laarni avatar image
Laarni asked

Hi. The API call for UpdatePlayerStatistics always returns an invalid parameters error?

I tried the call via the TryIt feature but i get the same result. Also i checked to find any sort of documentation in here and in all of your Youtube videos but nothing.

Obj C, Xcode

apis
10 |1200

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

brendan avatar image
brendan answered

We recently deprecated UpdateUserStatistics in favor of the newer UpdatePlayerStatistics, so it'll be a little while before we have a video on that specific topic. What are the details of the call you're making?

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

Laarni avatar image Laarni commented ·

I'd like to simply use that in order to set up my leaderboard by retrieving the statistics. On the documentation, i used the new api i guess. Anyways. I set up the statistic name on the players/Statistics and like what i said, with the TryIt, it does not work. Perhaps there s another way for the leaderboard?

0 Likes 0 ·
Laarni avatar image Laarni commented ·

Oww sorry, i did not see it but after checking the Playfab SDK for ios, it seems like the api call is still set for UpdateUserStatistics. I am going to try some midifications and check if it works. If yes, then i ll update you

0 Likes 0 ·
Laarni avatar image Laarni commented ·

But the TryIt is still showing invalparam.

0 Likes 0 ·
brendan avatar image brendan Laarni commented ·

Can you please send the specifics of how you're making the call? What are the parameters you are passing in?

0 Likes 0 ·
Laarni avatar image
Laarni answered
So as shown on the documentation for the API call UpdatePlayerStatistics, i am passing Statistics and Value as parameters. Statistics is the name of the statistics that i set on the playfab platform (Player/Statistics). Since the requirements for the call is "Statistics" for the name and StatisticUpdate for the type, i checked the requirements for StatisticsUpdate and i have to pass the Statistics and Value (String/int). 

 int i = _scoreLabel.text.integerValue;

    UpdateUserStatisticsRequest *request = [UpdateUserStatisticsRequest new];

    NSDictionary *stats = @{ @"Statistics": @{@"StatisticName":@"Stars", @"Value":[NSNumber numberWithInteger:i]}};

    request.UserStatistics = stats;

    [[PlayFabClientAPI GetInstance]

     UpdateUserStatistics:request success:^(UpdateUserStatisticsResult *result, NSObject *userData) {

         NSLog(@"Score OK!");

     } failure:^(PlayFabError *error, NSObject *userData) {

         NSLog(@"Score NON OK!");

         NSLog(@"%@",error.errorMessage);

     } withUserData:nil];

Following is the call used in the deprecated call. Since it s the same process than most of the calls, i just modified the objectForKeys to Statistics instead of UserStatistics so it will match the requested name in the new api call.


-(id)initWithDictionary:(NSDictionary*)properties

{

self = [super init];

if (!self) {

return nil;

}


if ([properties objectForKey:@"Statistics"]){

NSDictionary* member_list = [properties objectForKey:@"Statistics"];

NSMutableDictionary* mutable_storage = [NSMutableDictionary new];

for(NSString* key in member_list){

[mutable_storage setValue:[member_list objectForKey:key] forKey:key];

}self.Statistics = [mutable_storage copy];}



return self;

}

At the end,in the TryIt feature, i just put the Statistics name (Stars) and the error still comes with invalid input parameters.

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.

Laarni avatar image Laarni commented ·

I have checked everything and changed the whole call with the new API call that i did not think was in the obj c sdk. So even after that, still the same error. Perhaps i am not passing the right parameters.

So Question, Is it the Statistic name from the Player/Statistics?

0 Likes 0 ·
brendan avatar image
brendan answered

It sounds like you're saying you're trying to pass the same parameters to UpdatePlayerStatistics that you passed to UpdateUserStatistics, which won't work. The format of the call has changed. Could you please post the code snippet showing how you're making the call to UpdatePlayerStatistics? The code above is, as you point out, for the deprecated UpdateUserStatistics.

10 |1200

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

Laarni avatar image
Laarni answered
int i = _scoreLabel.text.integerValue;

    UpdatePlayerStatisticsRequest *request = [UpdatePlayerStatisticsRequest new];

    NSArray *stats = [@[@"Stars", [NSNumber numberWithInteger:i]] mutableCopy];

    //"Stars" is the name of the Statistic (String)
    //"i" is the Value (int)

    request.Statistics = stats;

    [[PlayFabClientAPI GetInstance]

     UpdatePlayerStatistics:request success:^(UpdatePlayerStatisticsResult *result, NSObject *userData) {

         NSLog(@"%@", result);

         NSLog(@"Score OK!");

     } failure:^(PlayFabError *error, NSObject *userData) {

         

         NSLog(@"Score NON OK!");

         NSLog(@"%@", error.errorMessage);

         

     } withUserData:nil];

//Follows the debug console

2016-11-01 11:58:24.993 CXXXXX[66915:878306] Score NON OK!
2016-11-01 11:58:24.993 CXXXXX[66915:878306] Invalid input parameters

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.

Laarni avatar image Laarni commented ·

So i have 2 elements to pass according to the API call. StatisticName and Value.

0 Likes 0 ·
Laarni avatar image Laarni commented ·

What should i put in the textifield for the TryIt ? Because it still return invalid parameters.

0 Likes 0 ·
brendan avatar image
brendan answered

The problem with the code shown is that you're not actually passing the StatisticName or Value as those parameters. You're using the UpdateUserStatistics style, where the contents of UserStatistics was like this:

"UserStatistics": { "Stars": 10 }

The UpdatePlayerStatstics call requires that you specify the StatisticName and Value for each stat being updated, so for the stat above, it should be like this:

"Statistics": [ { "StatisticName": "Stars", "Value": 10 } ]

So, in the TryIt for UpdatePlayerStatistics, you would put this in the Statistics field:

[ { "StatisticName": "Stars", "Value": 10 } ]

Also, I would recommend outputting the whole error, so that you get all the info. In particular, the errorDetails will usually have additional context which will help you to track down issues.

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.

Laarni avatar image Laarni commented ·

Ok. Got it. I ll try to find a way so i can put it that way in the Obj C language. Thanks.

Also, i know that the doc is pretty poor for the obj C. So while working on my app, whatever issue i have or good workaround to make everything work, i am writing it down so i can give it to you guys in order to perhaps provide it to other developpers.

0 Likes 0 ·
brendan avatar image brendan Laarni commented ·

Thanks! Our core documentation is all specific to the Web API calls, which are the underlying way all our SDKs use our service. We definitely want to get more language-specific documentation into each of the SDKs, and hopefully into the doc pages themselves in future. Any assistance the community can provide is always appreciated.

0 Likes 0 ·
Laarni avatar image
Laarni answered

I finally got it to work. My API call updates the Value but it returns a nil as result. The TryIt as well.

To get the update, should i use the GetUserStatistics API call?

//Debug console

Printing description of userData:

<nil>





//Tryit feature

{ "code": 200,
 "status": "OK",
 "data": {},
 "CallBackTimeMS": 174
}
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.

Laarni avatar image Laarni commented ·

Is it normal that the update also changes the value in the leaderboard when the score is below the previous one?

0 Likes 0 ·
brendan avatar image brendan Laarni commented ·

To retrieve the statistics, use GetPlayerStatistics. For the way the stat updates, it depends upon how you have set the aggregation method for the statistic. By default, the method is "Last", which means whatever the last value you submitted was will be accepted. If you want to only accept higher values, set the aggregation type to "Max".

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.