Interfaces🔗
MRGSAuthentication module contains several interfaces grouped by functionality, which provides access to different functionality of various social networks.
MRGSAuthentication interface (basic)🔗
MRGSAuthentication - main protocol (interface) for working with any authorization service, contains the basic set of methods that allow you to log in, log out, and get user data, information about tokens, permissions.
To obtain information about the type of authorization service and the current status of authorization, methods are provided:
To start the login procedure, the following methods are provided:
- (void)login:(void (^nullable)(NSError* error))completionHandler;
- (void)loginWithCompletionHandler:(void (^nullable)(MRGSAuthenticationCredential *credentials, NSError* error))completionHandler;
- (void)loginWithScopes: (NSArray<MRGSAuthenticationScope>*)requestedScopes completionHandler:(void (^nullable)(MRGSAuthenticationCredential *credentials, NSError* error))completionHandler;
In order to "log out" of a user’s account, a method is provided:
To get all the information about the current authorization status, user information, authorization status, methods are provided:
This interface is implemented by all authorization classes, regardless of the type of network. Thus, you can use these methods without explicitly indicating which service you are working with. For instance:
// Or any other networks
MRGSAuthentication _socialNetwork = MRGSAuthenticationSignInWithApple.Instance;
_socialNetwork.Login((MRGSAuthenticationCredential credentials, MRGSError error) => {
Debug.Log("Login result:\nCredentials: " + credentials + "\nError:\n" + error);
if (error == null) {
// Auth success
}
});
_socialNetwork.GetCurrentUser((MRGSAuthenticationUser user, MRGSError error) => {
Debug.Log("Result:\User: " + user + "\nError:\n" + error);
if (error == null) {
// Work with user data
}
});
_socialNetwork.GetAccessToken((MRGSAuthenticationAccessToken token, MRGSError error) =>
{
Debug.Log("Result:\Token: " + token + "\nError:\n" + error);
if (error == null) {
// Work with token info
}
else if (error.Code == (int)MRGSAuthenticationErrorCode.ConnectionFailed)
{
// No network, try later
}
else
{
// Logout user from app (MRGS will logout automatically in SDK)
}
});
_socialNetwork.Logout();
// Or any other network
id<MRGSAuthentication> _socialNetwork = [MRGSAuthenticationSignInWithApple sharedInstance];
[_socialNetwork loginWithCompletionHandler:^(MRGSAuthenticationCredential *credentials, NSError *error) {
NSLog(@"Result - %@. Error - %@", credentials, error);
if(!error){
// Authorization was successful.
}
}];
[_socialNetwork getCurrentUser:^(MRGSAuthenticationUser *user, NSError *error) {
NSLog(@"User - %@. Error - %@", user, error);
if(!error){
// User data work
}
}];
[_socialNetwork getAccessToken:^(MRGSAuthenticationAccessToken *token, NSError *error) {
if (!error) {
NSLog(@"getAccessToken result - %@", token);
} else {
NSLog(@"getAccessToken error - %@", error);
}
}];
[_socialNetwork logout];
// Or any other network
MRGSAuthentication socialNetwork = MRGSFacebook.getInstance();
socialNetwork.login(activity, new MRGSLoginCallback() {
@Override
public void onSuccess(MRGSCredentials credentials) {
// Authorization was successful.
}
@Override
public void onError(MRGSError error) {
// Authorization error
}
});
socialNetwork.getCurrentUser(new MRGSAuthentication.UserCallback() {
@Override
public void onSuccess(final MRGSUser user) {
}
@Override
public void onError(MRGSError error) {
}
});
socialNetwork.getAccessToken(new BiConsumer<MRGSAccessToken, MRGSError>() {
@Override
public void accept(MRGSAccessToken accessToken, MRGSError error) {
if (error != null) {
Log.d("MRGSAuthentication", "AccessToken error: " + error.getErrorText());
} else {
Log.d("MRGSAuthentication", "AccessToken success: " + authInfo);
}
}
});
socialNetwork.logout();
Also, most of our classes have fields for the delegate MRGSAuthenticationDelegate (OnExternalLogoutListener on Android). It contains methods:
// Setting
// 'this' conforms to 'IMRGSAuthenticationDelegate' protocol
<network>.Instance.Delegate = this;
// Implementation
// The method that is called when the user has logged out of the social network remotely, or his session has ended.
public void OnAuthenticationProviderDidLogoutUser(MRGSAuthentication provider, MRGSAuthenticationUser user){
Debug.Log("MRGSAuthentication - OnAuthenticationProviderDidLogoutUser: " + user + "\nNetwork: " + provider.SocialId().ToString());
}
// Method that is called if it is necessary to display the controller to authorize the user.
- (void)shouldPresentAuthorizationController:(UIViewController *)viewController;
// The method that is called when the user remotely logs out of the social network, or his session ends.
- (void)authenticationProvider:(id<MRGSAuthentication>)provider didLogoutUser:(MRGSAuthenticationUser *)user;
Possible errors🔗
List of errors that can be received:
typedef NS_ERROR_ENUM(kMRGSAuthenticationErrorDomain, MRGSAuthenticationErrorCode) {
MRGSAuthenticationErrorNotLoggedIn = -100,
MRGSAuthenticationErrorUserCanceledOperation = -101,
MRGSAuthenticationErrorNotAvailable = -102,
MRGSAuthenticationErrorOperationFailed = -105,
MRGSAuthenticationErrorInvalidInput = -107,
MRGSAuthenticationErrorNoScopePermission = -108,
MRGSAuthenticationErrorConnectionFailed = -109,
};
public enum MRGSAuthenticationError {
NOT_LOGGED_IN(-100, "User not logged in."),
USER_CANCELED(-101, "User canceled login."),
NOT_AVAILABLE(-102, "No available service."),
API_ERROR(-105, "Api error."),
INVALID_INPUT(-107, "Invalid input param."),
NO_SCOPE_PERMISSION(-108, "No scope permission."),
NO_CONNECTION(-109, "No internet connection."),
BROWSER_NOT_FOUND(-110, "Browser not found.");
}
MRGSAuthenticationGames interface (for gaming social networks)🔗
The protocol for working with gaming social networks is MRGSAuthenticationGames (MRGSGames on Android). It allows you to interact with player achievements and player rating tables.
Work with player achievements (Achievements)🔗
For a list of available achievements, use the method:
If successful, you will receive an array of objects of type MRGSAuthenticationAchievement that describe each achievement, otherwise an error will occur.
To set the progress for the user for a specific achievement, use the method:
The percentage of completion of the achievement and its identifier are passed to the method (can be obtained from previously received objects of the type MRGSAuthenticationAchievement), an error will be returned if it occurred.
To display the progress screen, use the method:
The callback will be called to the event that the user closes the achievement screen.
Working with player rating tables (Leaderboards)🔗
For a list of available rating tables, use the method:
If successful, you will receive an array of objects of type MRGSAuthenticationLeaderboard that describe each rating table, otherwise an error will occur.
To set points for the user for a specific rating table, use the method:
In the method points for the current user in the rating table and the identifier of a specific table (can be obtained from previously received objects of the type MRGSAuthenticationLeaderboard), an error will be returned if it occurs.
To display a screen with all rating tables, use the method:
The callback will be called to the event when the user closes the screen with all ratings.
To display a screen with a specific rating table, use the method:
The identifier of the rating table is passed to the method. The callback will be called to the event when the user closes the rating table screen.
To get the current rating for the user, or for all users of this rating, use the appropriate methods:
// For current user
void GetCurrentPlayerScoreForLeaderboard(string leaderboardId, MRGSAuthenticationLeaderboardTimeScope timeScope, MRGSAuthenticationLeaderboardCollectionType collection, Action<MRGSAuthenticationLeaderboardScore, MRGSError> completionHandler);
// For all users
void GetAllPlayersScoresForLeaderboard(string leaderboardId, MRGSAuthenticationLeaderboardTimeScope timeScope, MRGSAuthenticationLeaderboardCollectionType collection, Action<List<MRGSAuthenticationLeaderboardScore>, MRGSError> completionHandler);
// For current user
- (void)getCurrentPlayerScoreForLeaderboardWithId:(NSString *)leaderboardId timeScope:(MRGSAuthenticationLeaderboardTimeScope)timeScope collectionType:(MRGSAuthenticationLeaderboardCollectionType)collection completionHandler:(void (^nullable)(MRGSAuthenticationLeaderboardScore *score, NSError* error))completionHandler;
// For all users
- (void)getAllPlayersScoresForLeaderboardWithId:(NSString *)leaderboardId timeScope:(MRGSAuthenticationLeaderboardTimeScope)timeScope collectionType:(MRGSAuthenticationLeaderboardCollectionType)collection completionHandler:(void (^nullable)(NSArray<MRGSAuthenticationLeaderboardScore*> *scores, NSError* error))completionHandler;
MRGSLeaderBoards leaderBoards = getLeaderBoards();
// For current user
leaderBoards.getCurrentPlayerScore(final String leaderboardId, final int timeSpan, final int collection, final MRGSGetScoreCallback callback);
// For all users
leaderBoards.getTopScores(final String leaderboardId, final int timeSpan, final int collection, final int maxResult, final boolean forceLoad, final MRGSGetScoreListCallback callback);
The identifier of the rating table, the time for which it is necessary to collect data, the type of data collected (visibility for all, or only for friends) is transferred to the method. In response, an object, or an array of objects of type MRGSAuthenticationLeaderboardScore, describing the user rating points, will come.
MRGSAuthenticationSocialNetwork interface (for social networks)🔗
The protocol for working with social networks is MRGSAuthenticationSocialNetwork. It allows you to receive the user's friends, his profile picture, make game requests and invitations to the game, and also open the "share" page.
To get a user avatar with a given identifier and size, methods are provided:
To get a list of friends or users, methods are provided:
// Method for obtaining a list of friends identifiers of a user in a social network. (Important: for facebook, only the list of friends who installed this application will be returned.). Usually, this method requires permission to the friends list (specified in the loginWithScopes method).
void GetFriendsIds(Action<List<string>, MRGSError> completionHandler);
// Method for obtaining a user profile with the specified identifier in a social network. No additional permissions needed.
void GetUser(string userId, Action<MRGSAuthenticationUser, MRGSError> completionHandler);
// Method for obtaining multiple user profiles with the specified identifiers in a social network.
void GetUsers(List<string> usersIds, Action<List<MRGSAuthenticationUser>, MRGSError> completionHandler);
// Method for obtaining a list of friends identifiers of a user in a social network. (Important: for facebook, only the list of friends who installed this application will be returned.). Usually, this method requires permission to the friends list (specified in the loginWithScopes method).
- (void)getFriendsIds:(void (^nullable)(NSArray<NSString*>*ids, NSError* error))completionHandler;
// Method for obtaining a user profile with the specified identifier in a social network. No additional permissions needed.
- (void)getUserWithId:(NSString *)userId completionHandler:(void (^nullable)(MRGSAuthenticationUser *user, NSError* error))completionHandler;
// Method for obtaining multiple user profiles with the specified identifiers in a social network.
- (void)getUsersWithIds:(NSArray *)usersIds completionHandler:(void (^nullable)(NSArray<MRGSAuthenticationUser*> *users, NSError* error))completionHandler;
// Method for obtaining a list of friends of a user in a social network. (Important: for facebook, only the list of friends who installed this application will be returned.). Usually, this method requires permission to the friends list (specified in the loginWithScopes method).
void getFriends(FriendsCallback callback);
// Method for obtaining a user profile with the specified identifier in a social network. No additional permissions needed.
void getUserWithId(String userId, MRGSAuthentication.UserCallback callback);
// Method for obtaining multiple user profiles with the specified identifiers in a social network.
void getUsersWithId(List<String> userId, FriendsCallback callback);
In order to open the dialog for creating a new post in the current user’s feed with the specified parameters, use the method:
// Method for opening the dialog for creating a new post in the current user’s feed. It accepts an object of class MRGSAuthenticationPost, which describes the data with which the open dialog will be filled.
- (void)showPostOnWallDialog:(MRGSAuthenticationPost *)post completionHandler:(void (^nullable)(NSError* error))completionHandler;
To send invitations to the game and game requests (using them you can send "gifts" in some cases), as well as check incoming requests, methods are provided:
// Method for sending an invitation. The user will be shown a dialog for confirmation. In the response, if successful, an MRGSAuthenticationInvite object will be returned with filled in fields, such as request identifier, sent users. (Important: a window will open for facebook where the user himself selects friends to invite)
void SendInvite(MRGSAuthenticationInvite invite, Action<MRGSAuthenticationInvite, MRGSError> completionHandler);
// Method for sending a game request. The user will be shown a dialog for confirmation. In the response, if successful, an MRGSAuthenticationInvite object will be returned with filled in fields, such as request identifier, sent users. (Important: a window will open for facebook where the user himself selects friends to whom to send a request)
void SendGameRequest(MRGSAuthenticationInvite invite, Action<MRGSAuthenticationInvite, MRGSError> completionHandler);
// Method for receiving game requests or invitations sent by others to the current user. (The method is relevant only for Facebook, since there you need to manually delete requests.)
void GetGameRequests(Action<List<Dictionary<string, object>>, MRGSError> completionHandler);
// Method for sending an invitation. The user will be shown a dialog for confirmation. In the response, if successful, an MRGSAuthenticationInvite object will be returned with filled in fields, such as request identifier, sent users. (Important: a window will open for facebook where the user himself selects friends to invite)
- (void)sendInvite:(MRGSAuthenticationInvite *)invite completionHandler:(void (^nullable)(MRGSAuthenticationInvite* invite, NSError* error))completionHandler;
// Method for sending a game request. The user will be shown a dialog for confirmation. In the response, if successful, an MRGSAuthenticationInvite object will be returned with filled in fields, such as request identifier, sent users. (Important: a window will open for facebook where the user himself selects friends to whom to send a request)
- (void)sendGameRequest:(MRGSAuthenticationInvite*)invite completionHandler:(void (^nullable)(MRGSAuthenticationInvite* invite, NSError* error))completionHandler;
// Method for receiving game requests or invitations sent by others to the current user. (The method is relevant only for Facebook, since there you need to manually delete requests.)
-(void)getGameRequests:(MRGSAuthenticationGetGameRequestsHandler)completionHandler;
// Method for sending an invitation. The user will be shown a dialog for confirmation. In the response, if successful, an MRGSAuthenticationInvite object will be returned with filled in fields, such as request identifier, sent users. (Important: a window will open for facebook where the user himself selects friends to invite). Using the notInGame parameter, you can choose whether this is an invitation to install the game (true), or a game request (false)
void sendGameRequest(String title, String message, boolean notInGame, GameRequestResultCallback callback);
// Method for receiving game requests or invitations sent by others to the current user. (The method is relevant only for Facebook, since there you need to manually delete requests.)
void getGameRequests(GameRequestCallback callback);
// Method to delete the game request, after the game has processed it
void deleteGameRequest(String requestId, GameRequestDeleteCallback callback);
Created: 2020-03-02