question

brendan avatar image
brendan asked

API Calls of documentation to Unity C# Code

barcelo games
started a topic on Tue, 21 July 2015 at 10:53 AM

Hi all!

I really don´t understand the documentation API Calls for using them in Unity C# Code, for example, registering new user, like this:

POST https://[TitleID].playfabapi.com/Client/RegisterPlayFabUser
Content-Type: application/json;
{
  "TitleId": "1",
  "Username": "theuser",
  "Email": "me@here.com",
  "Password": "thepassword"
}

How can I translate that to C# to use it in Unity?

I´m using Unity 5 and the PlayFab SDK for Unity.

Thanks!

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

·
brendan avatar image
brendan answered

4 Comments
bluefox25 said on Tue, 21 July 2015 at 11:14 AM

Hi,

We've come here from Unity too and have been getting to grips with exactly the same issue regarding using Playful API calls in Sharp/Unity.

Check out my post of a few days ago that goes into the subject - HERE

Playfab API calls seem to follow a very similar format (as discussed in the post mentioned ).

The best way to learn about the API calls , it would seem, is to download the PlayFab Angry Bots Demo and the Playfab Union demos, both of which are written in CSharp and have good examples of code.

From GitHub - PlayFab Angry Bots download

From GitHub - Playfab Union Demo

Unfortunately they don't seem to cover every API call available. (?) As a suggestion for the guys at Playfab, I'd strongly recommend providing good, simple CSharp examples of all their APIs as soon as possible, laid out within the API descriptions on their website.

As for the API call you mentioned above. I believe this is the one you're after, pulled directly from the Angry Bots demo - CSharp script named 'PlayFabRegisterUser.cs'.

RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest();
request.TitleId = PlayFabData.TitleId;
request.Username = userNameField;
request.Email = emailField;
request.Password = passwordField;
Debug.Log("TitleId : "+request.TitleId);
PlayFabClientAPI.RegisterPlayFabUser(request,OnRegisterResult,OnPlayFabError);

GL

Bob


bluefox25 said on Tue, 21 July 2015 at 11:17 AM

P.S: Have to say, the hard work is rewarding. Playfab is pretty cool when you start getting your head around how to use it.


barcelo games said on Tue, 21 July 2015 at 11:25 AM

Thanks for the fast answer!

Yeah it will be amazing if the translate their API Calls to C# in the docs, it would be a lot easier.

I´m going to try the Angry Bots tutorial, I´ll update the post later.

Thanks again!


Brendan Vanous said on Tue, 21 July 2015 at 3:24 PM

Hi all,

Thanks for the suggestion on the samples. We are indeed working to provide more soon, but one thing to be aware of is that all of our API calls are indeed fully documented in the Web API reference guide: https://api.playfab.com/Documentation. All of our SDKs are wrappers around our Web API calls, so the signature (the call's name and parameters) will be the same regardless of which SDK you're using, and the documentation should always have examples in JSON of the calls and responses. Again, we will be providing more examples and documentation as we proceed, but the Web API will always be a good source for full info on how to use our APIs.

Brendan

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.

tohrque avatar image tohrque commented ·

Does the line:

PlayFabClientAPI.RegisterPlayFabUser(request, OnRegisterResult, OnPlayFabError);

Still work as far as the parameters for the function are concerned? Unity keeps giving me an error saying:

"No overload for method `RegisterPlayFabUser' takes `3' arguments"


This is what my method looks like currently:

public void Register() {
	var request = new RegisterPlayFabUserRequest()
	{
		TitleId = PlayFabSettings.TitleId,
		RequireBothUsernameAndEmail = false,
		Email = createEmailField.text,
		Username = createUsernameField.text,
		Password = createPasswordField.text
	};
	PlayFabClientAPI.RegisterPlayFabUser (request, HandleLoginSuccess, HandlePlayFabError);
}
0 Likes 0 ·
brendan avatar image brendan tohrque commented ·

What version of the SDK are you using? Looking at the source in GitHub, that call can be made with or without the customData parameter (since it defaults to null), so I would expect that to work.

0 Likes 0 ·
tohrque avatar image tohrque brendan commented ·

PlayFab SDK is version 2.9.160919

Unity is version 5.4.1f1

0 Likes 0 ·
Show more comments

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.