/// <summary> /// Signs the user in using a Facebook access token, returning a session identifier that can subsequently be used for API calls which require an authenticated user /// </summary> public static void LoginWithFacebook(LoginWithFacebookRequest request, LoginWithFacebookCallback resultCallback, ErrorCallback errorCallback) { request.TitleId = PlayFabSettings.TitleId ?? request.TitleId; if(request.TitleId == null) throw new Exception ("Must be have PlayFabSettings.TitleId set to call this method"); string serializedJSON = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings); Action<string,string> callback = delegate(string responseStr, string errorStr) { LoginResult result = null; PlayFabError error = null; ResultContainer<LoginResult>.HandleResults(responseStr, errorStr, out result, out error); if(error != null && errorCallback != null) { errorCallback(error); } if(result != null) { AuthKey = result.SessionTicket ?? AuthKey; if(resultCallback != null) { resultCallback(result); } } }; PlayFabHTTP.Post(PlayFabSettings.GetURL()+"/Client/LoginWithFacebook", serializedJSON, null, null, callback); }
/// <summary> /// Signs the user in using a Facebook access token, returning a session identifier that can subsequently be used for API calls which require an authenticated user /// </summary> public static async Task<PlayFabResult<LoginResult>> LoginWithFacebookAsync(LoginWithFacebookRequest request) { request.TitleId = PlayFabSettings.TitleId ?? request.TitleId; if(request.TitleId == null) throw new Exception ("Must be have PlayFabSettings.TitleId set to call this method"); object httpResult = await PlayFabHTTP.DoPost(PlayFabSettings.GetURL() + "/Client/LoginWithFacebook", request, null, null); if(httpResult is PlayFabError) { PlayFabError error = (PlayFabError)httpResult; if (PlayFabSettings.GlobalErrorHandler != null) PlayFabSettings.GlobalErrorHandler(error); return new PlayFabResult<LoginResult> { Error = error, }; } string resultRawJson = (string)httpResult; var serializer = JsonSerializer.Create(PlayFabSettings.JsonSettings); var resultData = serializer.Deserialize<PlayFabJsonSuccess<LoginResult>>(new JsonTextReader(new StringReader(resultRawJson))); LoginResult result = resultData.data; AuthKey = result.SessionTicket ?? AuthKey; return new PlayFabResult<LoginResult> { Result = result }; }
/// <summary> /// Signs the user in using a Facebook access token, returning a session identifier that can subsequently be used for API calls which require an authenticated user /// </summary> public static void LoginWithFacebook(LoginWithFacebookRequest request, ProcessApiCallback<LoginResult> resultCallback, ErrorCallback errorCallback, object customData = null) { request.TitleId = request.TitleId ?? PlayFabSettings.TitleId; if (request.TitleId == null) throw new Exception("Must be have PlayFabSettings.TitleId set to call this method"); string serializedJson = SimpleJson.SerializeObject(request, Util.ApiSerializerStrategy); Action<CallRequestContainer> callback = delegate(CallRequestContainer requestContainer) { ResultContainer<LoginResult>.HandleResults(requestContainer, resultCallback, errorCallback, LoginWithFacebookResultAction); }; PlayFabHTTP.Post("/Client/LoginWithFacebook", serializedJson, null, null, callback, request, customData); }
/// <summary> /// Function to be called to link Facebook user with PlayFab user /// (creates a new one if not exists, logins existing user if exists). /// </summary> /// <param name="facebookAccessToken">Facebook's access token</param> /// <param name="OnLoginCompletedCallback">Function to call after process ends</param> public void LoginWithFacebook(string facebookAccessToken, string facebookName, string facebookPictureURL, ProjectDelegates.PlayFabLoginCallback OnLoginCompletedCallback) { this.OnLoginCompletedCallback = OnLoginCompletedCallback; this.playerDisplayName = facebookName; this.playerPictureURL = facebookPictureURL; PlayFabSettings.TitleId = playFabGameID; LoginWithFacebookRequest facebookRequest = new LoginWithFacebookRequest(); facebookRequest.CreateAccount = true; facebookRequest.TitleId = playFabGameID; facebookRequest.AccessToken = facebookAccessToken; PlayFabClientAPI.LoginWithFacebook(facebookRequest, OnLoginCompleted, OnLoginError); }