public void AddButtonClicked(Button sender) { var playerIdText = sender.GetComponentInChildren<Text>(); if (playerIdText == null) return; if (playerIdText.text == "Add Friend") { var request = new AddFriendRequest() { FriendPlayFabId = sender.name }; Debug.Log(sender.name); PlayFabClientAPI.AddFriend(request, result => { if (result.Created) { sender.GetComponentInChildren<Text>().text = "Gift"; } }, error => { if (error.Error == PlayFabErrorCode.UsersAlreadyFriends) { sender.GetComponentInChildren<Text>().text = "Gift"; } }); } else if (playerIdText.text == "Gift") { PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest() { FunctionName = "grantItemToPlayer", FunctionParameter = new {benefiter = sender.name}, GeneratePlayStreamEvent = false}, urlResult => { Debug.Log("success cloud scipt!"); }, error => { Debug.Log(error.ErrorMessage); }); } }
/// <summary> /// Adds the PlayFab user, based upon a match against a supplied unique identifier, to the friend list of the local user /// </summary> public static void AddFriend(AddFriendRequest request, AddFriendCallback resultCallback, ErrorCallback errorCallback) { if (AuthKey == null) throw new Exception ("Must be logged in to call this method"); string serializedJSON = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings); Action<string,string> callback = delegate(string responseStr, string errorStr) { AddFriendResult result = null; PlayFabError error = null; ResultContainer<AddFriendResult>.HandleResults(responseStr, errorStr, out result, out error); if(error != null && errorCallback != null) { errorCallback(error); } if(result != null) { if(resultCallback != null) { resultCallback(result); } } }; PlayFabHTTP.Post(PlayFabSettings.GetURL()+"/Client/AddFriend", serializedJSON, "X-Authorization", AuthKey, callback); }
/// <summary> /// Adds the PlayFab user, based upon a match against a supplied unique identifier, to the friend list of the local user. At least one of FriendPlayFabId,FriendUsername,FriendEmail, or FriendTitleDisplayName should be initialized. /// </summary> public static void AddFriend(AddFriendRequest request, ProcessApiCallback<AddFriendResult> resultCallback, ErrorCallback errorCallback, object customData = null) { if (_authKey == null) throw new Exception("Must be logged in to call this method"); string serializedJson = SimpleJson.SerializeObject(request, Util.ApiSerializerStrategy); Action<CallRequestContainer> callback = delegate(CallRequestContainer requestContainer) { ResultContainer<AddFriendResult>.HandleResults(requestContainer, resultCallback, errorCallback, null); }; PlayFabHTTP.Post("/Client/AddFriend", serializedJson, "X-Authorization", _authKey, callback, request, customData); }
public static void AddFriend(string email) { var request = new AddFriendRequest() { FriendEmail = email }; PlayFabClientAPI.AddFriend(request, (result) => { Debug.Log("Friend added"); GetFriendsList(); }, (error) => { Debug.Log("Cant add to friends list"); Debug.Log(error.ErrorMessage); Debug.Log(error.ErrorDetails); }); }
/// <summary> /// Adds the PlayFab user, based upon a match against a supplied unique identifier, to the friend list of the local user. At least one of FriendPlayFabId,FriendUsername,FriendEmail, or FriendTitleDisplayName should be initialized. /// </summary> public static async Task<PlayFabResult<AddFriendResult>> AddFriendAsync(AddFriendRequest request) { if (AuthKey == null) throw new Exception ("Must be logged in to call this method"); object httpResult = await PlayFabHTTP.DoPost(PlayFabSettings.GetURL() + "/Client/AddFriend", request, "X-Authorization", AuthKey); if(httpResult is PlayFabError) { PlayFabError error = (PlayFabError)httpResult; if (PlayFabSettings.GlobalErrorHandler != null) PlayFabSettings.GlobalErrorHandler(error); return new PlayFabResult<AddFriendResult> { Error = error, }; } string resultRawJson = (string)httpResult; var serializer = JsonSerializer.Create(PlayFabSettings.JsonSettings); var resultData = serializer.Deserialize<PlayFabJsonSuccess<AddFriendResult>>(new JsonTextReader(new StringReader(resultRawJson))); AddFriendResult result = resultData.data; return new PlayFabResult<AddFriendResult> { Result = result }; }