Exemple #1
0
        public void RequestFriends(System.Action CallbackHandler)
        {
            if (CallbackHandler != null)
            {
                OnGetFriendsHandler += CallbackHandler;
            }
            string query = "/me/friends";

            FB.API(query, HttpMethod.GET,
                   (IGraphResult result) => {
#if !RELEASE_VERSION
                if (verbose)
                {
                    Debug.Log(result.RawResult);
                }
#endif
                string json     = result.RawResult;
                UsersList users = new UsersList();
                users.Init(json);
                //TODO verificar en el pagin si es el listado completo
                //si no lo es, no enviar evento hasta completar el listado
                if (OnGetFriendsHandler == null)
                {
                    return;
                }
                friends = users;
                OnGetFriendsHandler();
                //limpiamos el delegate
                System.Delegate[] list = OnGetFriendsHandler.GetInvocationList();
                foreach (System.Delegate del in list)
                {
                    OnGetFriendsHandler -= (System.Action)del;
                }
            }
                   );
        }
Exemple #2
0
        IEnumerator GetListOfScores(UsersList friendList, UnityWebRequest www)
        {
            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
                yield break;
            }

#if !RELEASE_VERSION
            if (verbose)
            {
                Debug.LogFormat("<color=blue>{0}</color>",
                                www.downloadHandler.text);
            }
#endif
            WWWForm form = new WWWForm();
            Dictionary <string, object> result =
                (Dictionary <string, object>)MiniJSON.Json.Deserialize(www.downloadHandler.text);
            if (result.ContainsKey("error"))
            {
                Debug.Log(result ["error"]);
                string error = (string)result ["error"];
                switch (error)
                {
                case "USER_NO_EXIST":
                    form.AddField("action", "register");
                    form.AddField("fbid", user_id);
                    form.AddField("game", Application.identifier);
                    form.AddField("username", user_name);
                    www = UnityWebRequest.Post(serverURL, form);
                    www.chunkedTransfer = false;
                    yield return(new WaitForSeconds(1f));

                    yield return(GetListOfScores(friendList, www));

                    yield break;

                default:
                    yield break;
                }
            }
            //registramos el usuario correctamente
            if (result.ContainsKey("success"))
            {
                bool success = (bool)result ["success"];
                if (success)
                {
                    GetFriendsListForScores();
                }
                yield break;
            }
            //Mostramos los datos
            ScoresList scoreList = new ScoresList();
            scoreList.Init(www.downloadHandler.text);
            //
            if (OnGetScoresHandler == null)
            {
                yield break;
            }
            this.scores = scoreList;
            OnGetScoresHandler();
            ClearDelegate(OnGetScoresHandler);
        }