public static API ( string query, HttpMethod method, FacebookDelegate callback = null, string>.Dictionary |
||
query | string | |
method | HttpMethod | |
callback | FacebookDelegate | |
formData | string>.Dictionary | |
Результат | void |
public void LoadUserFriends() { FB.API("/me/friends?fields=id,first_name", Facebook.HttpMethod.GET, CallbackLoadFriends); }
public void QueryScores() { SetScore(); FB.API("/app/scores?fields=score,user.limit(30)", HttpMethod.GET, ScoresCallback); }
//-------------------------------------- // Scores API // https://developers.facebook.com/docs/games/scores //------------------------------------ //Read score for a player public void LoadPlayerScores() { FB.API("/" + UserId + "/scores", FB_HttpMethod.GET, OnLoaPlayrScoresComplete); }
// load friend's scores public void FacebookGetScores() { FB.API("/app/scores", Facebook.HttpMethod.GET, ProcessRanking); }
//GET ALL achievements of APP public void GetAllAppAchievements() { FB.API(FB.AppId + "/achievements", Facebook.HttpMethod.GET, HandleGetAllAppAchievements); }
private void GetUserData() { string query = "/me?fields=name,email"; FB.API(query, HttpMethod.GET, OnGetUserDataFinished); }
public void getUserName() { FB.API("/me?fields=first_name", HttpMethod.GET, DisplayUsername); }
// // Authen private void _AuthenFacebook(System.Action <_AuthenFacebookResult> callback) { Log("_AuthenFacebook"); if (!FB.IsInitialized) { Log("Uninitialized"); callback(new _AuthenFacebookResult { ErrorCode = 1 }); return; } if (FB.IsLoggedIn) { FB.LogOut(); } // Login to facebook Log("Login to facebook"); FB.LogInWithReadPermissions(new List <string>() { "public_profile", "email", "user_friends" }, result => { if (result == null || string.IsNullOrEmpty(result.Error)) { Log("Facebook API get name"); FB.API(AccessToken.CurrentAccessToken.UserId, HttpMethod.GET, fbResult => { if (fbResult == null || string.IsNullOrEmpty(fbResult.Error)) { Log("Success"); callback(new _AuthenFacebookResult { ErrorCode = 0, AvatarUrl = "https://graph.facebook.com/" + AccessToken.CurrentAccessToken.UserId + "/picture?type=square", Name = fbResult.ResultDictionary["name"].ToString(), AccessToken = AccessToken.CurrentAccessToken.TokenString }); } else { Log("Fail"); callback(new _AuthenFacebookResult { ErrorCode = 1, ErrorMsg = fbResult.Error }); } }); } else { Log("Fail - " + result.Error); callback(new _AuthenFacebookResult { ErrorCode = 1, ErrorMsg = result.Error }); } }); }
void GetUserName() { FB.API("/me?fields=first_name", HttpMethod.GET, GettingNameCallback); }
protected override void SendSuccessResult() { if (string.IsNullOrEmpty(this.accessToken)) { this.SendErrorResult("Empty Access token string"); return; } // Make a Graph API call to get FBID FB.API( "/me?fields=id&access_token=" + this.accessToken, HttpMethod.GET, delegate(IGraphResult graphResult) { if (!string.IsNullOrEmpty(graphResult.Error)) { this.SendErrorResult("Graph API error: " + graphResult.Error); return; } string facebookID = graphResult.ResultDictionary["id"] as string; // Make a Graph API call to get Permissions FB.API( "/me/permissions?access_token=" + this.accessToken, HttpMethod.GET, delegate(IGraphResult permResult) { if (!string.IsNullOrEmpty(permResult.Error)) { this.SendErrorResult("Graph API error: " + permResult.Error); return; } // Parse permissions List <string> grantedPerms = new List <string>(); List <string> declinedPerms = new List <string>(); var data = permResult.ResultDictionary["data"] as List <object>; foreach (Dictionary <string, object> dict in data) { if (dict["status"] as string == "granted") { grantedPerms.Add(dict["permission"] as string); } else { declinedPerms.Add(dict["permission"] as string); } } // Create Access Token var newToken = new AccessToken( this.accessToken, facebookID, DateTime.UtcNow.AddDays(60), grantedPerms, DateTime.UtcNow); var result = (IDictionary <string, object>)MiniJSON.Json.Deserialize(newToken.ToJson()); result.Add("granted_permissions", grantedPerms); result.Add("declined_permissions", declinedPerms); if (!string.IsNullOrEmpty(this.CallbackID)) { result[Constants.CallbackIdKey] = this.CallbackID; } if (this.Callback != null) { this.Callback(new ResultContainer(result)); } }); }); }
public FB_GrapRequest_V6(string query, HttpMethod method, SPFacebook.FB_Delegate callback, WWWForm form) { _Callback = callback; FB.API(query, method, GraphCallback, form); }
private Task Needs_Login() { return(new Task() { Mission = "Needs_Login", Action = (seekTo, currentTask, nextTask, delivery) => { if (FB.IsLoggedIn) { if (File.Exists(Config.Directories.Identity)) { FileStream stream = new FileStream(Config.Directories.Identity, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(stream); string json = reader.ReadToEnd(); reader.Close(); stream.Close(); Variables.Self = JsonConvert.DeserializeObject <JsonSelf>(json); if (Variables.Self.fbId != AccessToken.CurrentAccessToken.UserId) { File.Delete(Config.Directories.Identity); currentTask(null); } else { nextTask(null); } } else { FB.API("/me?fields=name,email,picture.type(large)", HttpMethod.POST, (graphResult) => { Variables.Self = new JsonSelf() { key = "", fbId = graphResult.ResultDictionary["id"].ToString(), email = graphResult.ResultDictionary["email"].ToString(), name = graphResult.ResultDictionary["name"].ToString(), picture = ((graphResult.ResultDictionary["picture"] as Dictionary <string, object>)["data"] as Dictionary <string, object>)["url"].ToString() }; (Variables.UI["txtConsole"] as UIText).Element.text = "Logged you in..."; #if UNITY_EDITOR nextTask(null); #endif #if !UNITY_EDITOR OneSignal.IdsAvailable(HandleID); Variables.nextTask = nextTask; #endif }); } } else { Directives.App_First = true; (Variables.UI["txtConsole"] as UIText).Element.text = "Need to log you in..."; List <string> perms = new List <string>() { "public_profile", "email", "user_friends" }; FB.LogInWithReadPermissions(perms, (result) => { if (result.Cancelled) { Application.Quit(); } if (FB.IsLoggedIn) { FB.API("/me?fields=name,email,picture.type(large)", HttpMethod.POST, (graphResult) => { Variables.Self = new JsonSelf() { key = "", fbId = graphResult.ResultDictionary["id"].ToString(), email = graphResult.ResultDictionary["email"].ToString(), name = graphResult.ResultDictionary["name"].ToString(), picture = ((graphResult.ResultDictionary["picture"] as Dictionary <string, object>)["data"] as Dictionary <string, object>)["url"].ToString() }; (Variables.UI["txtConsole"] as UIText).Element.text = "Logged you in..."; #if UNITY_EDITOR nextTask(null); #endif #if !UNITY_EDITOR OneSignal.IdsAvailable(HandleID); Variables.nextTask = nextTask; #endif }); } }); } } }); }
public void GetFacebookScores() { FB.API("/app/scores?fields=score,user.limit(30)", HttpMethod.GET, GetScoresCallback); }
public void LoginButton(bool hideLoading = true) { //MobilePlugin.getInstance().ShowToast("Click login"); string error = ""; //AudioControl.DPlaySound("Click 1"); try { if (FB.IsInitialized) { if (FB.IsLoggedIn) { HideLoginDialog(); GetFriendsList(); loginButton.gameObject.SetActive(false); transform.FindChild("Button").FindChild("ButtonShowMessage").gameObject.SetActive(true); transform.FindChild("Button").FindChild("ButtonInviteFriend").gameObject.SetActive(true); transform.FindChild("Button").FindChild("ButtonHelpFriend").gameObject.SetActive(true); } else { DFB.FBLogin(result => { //MobilePlugin.getInstance().ShowToast("FB.IsLoggedIn " + FB.IsLoggedIn); if (FB.IsLoggedIn) { loginButton.gameObject.SetActive(false); transform.FindChild("Button").FindChild("ButtonShowMessage").gameObject.SetActive(true); transform.FindChild("Button").FindChild("ButtonInviteFriend").gameObject.SetActive(true); transform.FindChild("Button").FindChild("ButtonHelpFriend").gameObject.SetActive(true); //get friends list GetFriendsList(); //count message CountMessage(); //Get info user if (String.IsNullOrEmpty(PlayerPrefs.GetString(DataCache.FB_ID, ""))) { FB.API("v2.2/me", Facebook.HttpMethod.GET, rsl => { IDictionary dict1 = Json.Deserialize(rsl.Text) as IDictionary; if (dict1 != null && dict1["id"] != null) { DFB.UserId = "" + dict1["id"]; DFB.UserName = "" + dict1["name"]; PlayerPrefs.SetString(DataCache.FB_ID, DFB.UserId); PlayerPrefs.SetString(DataCache.FB_USER, DFB.UserName); try { AudioControl.getMonoBehaviour().StartCoroutine(DHS.PostMeInfo(DFB.UserId, DFB.UserName, "" + dict1["locale"], "" + dict1["last_name"])); } catch (Exception e) { ShowConfirm(); Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message); error = "" + e.Message; } } }); } else { DFB.UserId = PlayerPrefs.GetString(DataCache.FB_ID); DFB.UserName = PlayerPrefs.GetString(DataCache.FB_USER); } } else { ShowConfirm(); } }); } } else { DFB.FBInit(); ShowConfirm(); } } catch (Exception e) { ShowConfirm(); Debug.Log("--------------------Error Login FB-------------------" + e.Message); error = "" + e.Message; } //MobilePlugin.getInstance().ShowToast("error " + error); }
public void GetInformation() { FB.API("me?fields=id,email,first_name,last_name", Facebook.HttpMethod.GET, UserCallBack); }
void GetPicture(string id) { FB.API("/" + id + "/picture", HttpMethod.GET, this.ProfilePhotoCallback); }
void CheckDownloadPicture() { if (_currDownloadId.Length == 0 && _pictureDownloadIds.Count > 0) { var fristEnum = _pictureDownloadIds.GetEnumerator(); fristEnum.MoveNext(); _currDownloadId = fristEnum.Current; Debug.LogWarning("cccc " + _currDownloadId); FB.API(string.Format("/{0}/picture?height=128&width=128", _currDownloadId), HttpMethod.GET, delegate(IGraphResult result) { if (debugInfo) { FacebookHelperDebug("CheckDownloadPicture"); } if (result == null) { if (debugInfo) { FacebookHelperDebug("CheckDownloadPicture Null Response\n"); } return; } else { if (!string.IsNullOrEmpty(result.Error)) { if (debugInfo) { FacebookHelperDebug("CheckDownloadPicture Error Response:\n" + result.Error); } } else if (result.Cancelled) { if (debugInfo) { FacebookHelperDebug("CheckDownloadPicture Cancelled Response:\n" + result.RawResult); } } else if (!string.IsNullOrEmpty(result.RawResult)) { if (debugInfo) { FacebookHelperDebug("CheckDownloadPicture Success Response:\n"); } if (_pictureDownloadIds.Contains(_currDownloadId)) { Sprite pic = Sprite.Create(result.Texture, new Rect(0, 0, result.Texture.width, result.Texture.height), Vector2.one * 0.5f); if (_pictures.ContainsKey(_currDownloadId)) { _pictures[_currDownloadId] = pic; } else { _pictures.Add(_currDownloadId, pic); } _pictureDownloadIds.Remove(_currDownloadId); ModelBinder.OnPropChanged(ModelPropKey.Picture.ToString(), _currDownloadId); _currDownloadId = ""; Debug.Log("id dddd " + _currDownloadId); CheckDownloadPicture(); } } else { if (debugInfo) { FacebookHelperDebug("CheckDownloadPicture Empty Response\n"); } } } }); } }
public void ReadScores() { FB.API("/me/objects/object", HttpMethod.GET, APICallBack); }
private void CallFBAPI() { FB.API(ApiQuery, Facebook.HttpMethod.GET, Callback); }
public void GetFriendsPicture() { FB.API("me/friends?fields=picture", HttpMethod.GET, RequestFriendsCallback); }
//------------------------------------------------------------- // FacebookFriends //------------------------------------------------------------- public void FacebookGetFriends() { Debug.Log("FacebookFriends"); FB.API("/me/friends?fields=id,name,picture", Facebook.HttpMethod.GET, FriendsCallback); //FB.API("/me/friends", Facebook.HttpMethod.GET, FriendsCallback); }
private void LoginCallback(ILoginResult result) { if (FB.IsLoggedIn) { // facebook ログインの情報を使って NCMB にログインする var aToken = Facebook.Unity.AccessToken.CurrentAccessToken; NCMBFacebookParameters parameters = new NCMBFacebookParameters(aToken.UserId, aToken.TokenString, aToken.ExpirationTime); NCMBUser user = new NCMBUser(); user.AuthData = parameters.param; user.LogInWithAuthDataAsync((NCMBException e) => { if (e != null) { Debug.LogError("Failed to login: "******"Failed to fetch: " + ex.ErrorMessage); } else { if (string.IsNullOrEmpty(user.Email)) { Dictionary <string, string> formData = new Dictionary <string, string>() { }; FB.API("/me?fields=id,email", HttpMethod.GET, (IGraphResult r) => { if (r.Error != null) { Debug.Log(r.Error); } else { Debug.Log(r.ResultDictionary.ToJson()); string email = r.ResultDictionary["email"].ToString(); user.Email = email; user.SaveAsync((NCMBException exc) => { if (exc != null) { Debug.LogError("Failed to save: " + ex.ErrorMessage); } else { Debug.Log("Saved email data successfully."); } }); } } , formData); } } }); } }); } else { Debug.Log("User cancelled login"); } }
public void FacebookGetMyInfo() { FB.API("/me?", Facebook.HttpMethod.GET, MyInfoCallback); }
/// <summary> /// Get SEND requests. /// Return callback(requests, error). /// </summary> public static void GetSendRequests(Action <List <RequestData>, string> callback) { FB.API("/me/apprequests?fields=id,from,data,action_type", HttpMethod.GET, (result) => { if (!string.IsNullOrEmpty(result.Error)) { callback(null, result.Error); } else { if (!string.IsNullOrEmpty(result.RawResult)) { var pendingRequests = Json.Deserialize(result.RawResult) as Dictionary <string, object>; var pendingRequestsData = pendingRequests["data"] as List <object>; if (pendingRequestsData != null && pendingRequestsData.Count > 0) { var list = new List <RequestData>(); object idH; object fromH; object dataH; object actionTypeH; foreach (var entry in pendingRequestsData) { var requestItem = entry as Dictionary <string, object>; string id = ""; string fromId = ""; string fromName = ""; FBObjectType objectType = FBObjectType.None; if (requestItem.TryGetValue("id", out idH)) { id = idH.ToString(); } if (requestItem.TryGetValue("from", out fromH)) { var from = (Dictionary <string, object>)fromH; fromId = from["id"].ToString(); fromName = from["name"].ToString(); } if (requestItem.TryGetValue("data", out dataH)) { string item = dataH.ToString(); if (item == Coin) { objectType = FBObjectType.Coin; } else if (item == Mana) { objectType = FBObjectType.Mana; } // else if (item == InviteToGetCoin) objectType = FBObjectType.InviteCoin; // else if (item == InviteToGetMana) objectType = FBObjectType.InviteMana; else { objectType = FBObjectType.Unknown; } } if (requestItem.TryGetValue("action_type", out actionTypeH)) { if (actionTypeH.ToString() == "send") { list.Add(new RequestData(id, fromId, fromName, FBActionType.Send, objectType)); } } } callback(list, null); } else { callback(null, null); } } else { callback(null, null); } } }); }
private void QueryScores() { FB.API("/app/scores?fields=score,user.limit(20)", Facebook.HttpMethod.GET, ScoresCallback); }
/// <summary> /// Get ASK requests. /// Return callback(requests, error). /// </summary> public static void GetAskRequests(Action <List <RequestData>, string> callback) { FB.API("/me/apprequests?fields=id,from,data,action_type", HttpMethod.GET, (result) => { if (!string.IsNullOrEmpty(result.Error)) { callback(null, result.Error); } else { if (!string.IsNullOrEmpty(result.RawResult)) { var pendingRequests = Json.Deserialize(result.RawResult) as Dictionary <string, object>; var pendingRequestsData = pendingRequests["data"] as List <object>; if (pendingRequestsData != null && pendingRequestsData.Count > 0) { var list = new List <RequestData>(); object idH; object fromH; object dataH; object actionTypeH; foreach (var entry in pendingRequestsData) { var requestItem = entry as Dictionary <string, object>; string id = ""; string fromId = ""; string fromName = ""; FBObjectType objectType = FBObjectType.None; if (requestItem.TryGetValue("id", out idH)) { id = idH.ToString(); } if (requestItem.TryGetValue("from", out fromH)) { var from = (Dictionary <string, object>)fromH; fromId = from["id"].ToString(); fromName = from["name"].ToString(); } if (requestItem.TryGetValue("data", out dataH)) { string item = dataH.ToString(); if (item == Coin) { objectType = FBObjectType.Coin; } else if (item == Mana) { objectType = FBObjectType.Mana; } // else if (item == InviteToGetCoin) // { // // Send coin // SendObject(null, InviteToGetCoin, Settings.SendCoinByInviteTitle, string.Format(Settings.SendCoinByInviteMessage, Settings.CoinByInvite), (error) => { // if (!string.IsNullOrEmpty(error)) // { // //Log.Debug("Invite error: " + error); // } // }, fromId); // // DeleteRequest(id); // // callback(null, null); // // return; // } // else if (item == InviteToGetMana) // { // // Send mana // SendObject(null, InviteToGetMana, Settings.SendManaByInviteTitle, string.Format(Settings.SendManaByInviteMessage, Settings.ManaByInvite), (error) => { // if (!string.IsNullOrEmpty(error)) // { // //Log.Debug("Invite error: " + error); // } // }, fromId); // // DeleteRequest(id); // // callback(null, null); // // return; // } else { objectType = FBObjectType.Unknown; } } if (requestItem.TryGetValue("action_type", out actionTypeH)) { if (actionTypeH.ToString() == "askfor") { list.Add(new RequestData(id, fromId, fromName, FBActionType.AskFor, objectType)); } } } callback(list, null); } else { callback(null, null); } } else { callback(null, null); } } }); }
//-------------------------------------- // Requests API //-------------------------------------- public void LoadPendingRequests() { FB.API("/" + UserId + "/apprequests?fields=id,application,data,message,action_type,from,object", FB_HttpMethod.GET, OnRequestsLoadComplete); }
private void OnGetScore(IGraphResult result) { //khoi tao lai list doi thu score if (getEnemy && Modules.countryEnemy != 1 && !checkScore) { Modules.fbAvatarEnemy = new List <string>(); Modules.fbNameEnemy = new List <string>(); Modules.fbHighScore = new List <float>(); } //thuc hien khac scoresList = DeserializeScores(result.RawResult); if (panelGetInfo != null) { Destroy(panelGetInfo); } panelGetInfo = Instantiate(panelListFriend, Vector3.zero, Quaternion.identity) as GameObject; Transform panelContent = panelGetInfo.transform.Find("Content"); Transform panelItem = panelContent.transform.Find("Item"); int index = 0; //Modules.textDebug.text += "\nGET: " + result.RawResult; //Modules.textDebug.text += "\nGET: ScoresList: " + scoresList.Count; foreach (object score in scoresList) { var entry = (Dictionary <string, object>)score; var user = (Dictionary <string, object>)entry["user"]; GameObject newItem = panelItem.gameObject; if (index > 0) { newItem = Instantiate(panelItem.gameObject, Vector3.zero, Quaternion.identity) as GameObject; newItem.transform.SetParent(panelContent, false); } if (index % 2 != 0) { newItem.GetComponent <Image>().color = Modules.colorListLine; } Transform tranAvatar = newItem.transform.Find("Avatar"); Transform tranName = newItem.transform.Find("Name"); Transform tranScore = newItem.transform.Find("Score"); Transform tranIndex = newItem.transform.Find("Index"); Image fbAvatar = tranAvatar.GetComponent <Image>(); Text fbName = tranName.GetComponent <Text>(); Text fbScore = tranScore.GetComponent <Text>(); Text fbIndex = tranIndex.GetComponent <Text>(); fbName.text = user["name"].ToString().Split(' ')[0]; int scoreNow = Modules.IntParseFast(entry["score"].ToString()); if (getEnemy && Modules.countryEnemy != 1 && !checkScore && scoreNow >= Modules.totalScore) { Modules.fbNameEnemy.Add(fbName.text); Modules.fbHighScore.Add(scoreNow); Modules.fbAvatarEnemy.Add("https" + "://graph.facebook.com/" + user["id"] + "/picture?g&width=128&height=128"); //Modules.textDebug.text += "\nADD: " + fbName.text; } fbScore.text = scoreNow.ToString(); if (checkScore) { oldScore = scoreNow; } fbIndex.text = (index + 1).ToString(); FB.API(GetPictureURL(user["id"].ToString(), 128, 128), HttpMethod.GET, delegate(IGraphResult pictureResult) { if (pictureResult.Error != null) // if there was an error { Debug.Log(pictureResult.Error); } else // if everything was fine { if (fbAvatar) { fbAvatar.sprite = Sprite.Create(pictureResult.Texture, new Rect(0, 0, 128, 128), new Vector2(0, 0)); } } }); index++; } if (checkScore) { if (oldScore >= Modules.totalScore) { postNewScore = false; } else { postNewScore = true; } PostScore(false); } else { isGetDone = true; getEnemy = false; } }
//Read scores for players and friends public void LoadAppScores() { FB.API("/" + AppId + "/scores", FB_HttpMethod.GET, OnAppScoresComplete); }
public static void GetInvitableFriends() { string queryString = "/me/invitable_friends?fields=id,name&limit=100"; FB.API(queryString, HttpMethod.GET, GetInvitableFriendsCallback); }