Authentication
Before you are able to use any of the feature from CP Social, you'll have to authenticate the player. This can be done using the CP_Social
class. CP Social is the main entry point for all the available social features.
Initialization
To make sure CP Social understands what platform it it running on, it's mandatory that you call:
CP_Social.Init();
As soon as your app/game starts.
To know when CP Social has been initialised you can add a listener on the initialized callback, for example:
//Unity awake
void Awake()
{
CP_Social.Initialized += () =>
{
Debug.Log("CP Social initialized");
};
CP_Social.Init();
}
NOTE
It's doesn't matter if CP Social has already initialized before you add the listner to the callback. If CP Social is already initialized the added listener will still be notified.
Authentication service
After intialization you are still not able to use any features of CP Social, you'll have to authenticate the player. To do this you can get the only available service at this time the Authentication service.
This returned service will be an instance of the ICP_AuthService
using this interface you can authenticate the player, the following example will show you some example code how you can to this:
//Unity start
void Start()
{
CP_Social.GetAuthenticationService().Authenticate((result) =>
{
Debug.Log("Authentication: " + result.success);
if (result.success)
{
CP_UserInfo info = result.value;
Debug.Log("User info: " + info.userId + " " + info.userName + " " + info.userNickName);
}
});
}
When the authentication process is complete the CP_Social class has an event you can add multiple listners to called Authenticated
for example:
//Unity start
void Start()
{
CP_Social.Authenticated += OnSocialPlatformInitialized;
}
private void OnSocialPlatformInitialized(CP_AuthenticationResult result)
{
if (result.success)
{
CP_UserInfo info = result.value;
Debug.Log("User info: " + info.UserId + " " + info.UserName + " " + info.UserNickName);
}
}
NOTE
It's doesn't matter if CP Social has already authenticated before you add the listner to the callback. If CP Social is already authenticated the added listener will be called with the same values as the first callback.
All in one
If you want to initialize and authenticate all in one go here is a handy snippit you can use in your game:
void Awake()
{
CP_Social.Initialized += () =>
{
CP_Social.GetAuthenticationService().Authenticate((result) =>
{
Debug.Log("Authentication: " + result.success);
if (result.success)
{
CP_UserInfo info = result.value;
Debug.Log("User info: " + info.UserId + " " + info.UserName + " " + info.UserNickName);
}
});
};
CP_Social.Init();
}
Next steps
Afther authenticating the player CP Social will be fully initialized and all features can be used.