Exemplo n.º 1
0
 /**
  * Initializes Facebook App
  **/
 private void SetInit()
 {
     if (FB.IsInitialized)
     {
         Debug.Log("Fb init is done");
         // Signal an app activation App Event
         FB.ActivateApp();
         //Check if they already logged in or not before, to update button text
         if (FB.IsLoggedIn)
         {
             this.loggedIn = true;
             loginOutbtn.GetComponentInChildren <Text>().text = "Logout";
             datahandler.SetIsLoggedIn(true);
             FB.API("me?fields=name", Facebook.Unity.HttpMethod.GET, GetFacebookData);
             this.accessToken = AccessToken.CurrentAccessToken;
             credentials      = FacebookAuthProvider.GetCredential(this.accessToken.TokenString);
             FirebaseLogin();
         }
         else
         {
             this.loggedIn = false;
             loginOutbtn.GetComponentInChildren <Text>().text = "Login";
             datahandler.SetIsLoggedIn(false);
         }
     }
     else
     {
         Debug.Log("Failed to Initialize the Facebook SDK");
     }
 }
Exemplo n.º 2
0
    void LoginPlayfabWithFBAccount(Facebook.Unity.AccessToken token)
    {
        Debug.Log("LoginPlayfabWithFBAccount " + token);
        var request = new LoginWithFacebookRequest {
            AccessToken = token.TokenString
        };

        request.TitleId       = PlayFabSettings.TitleId;
        request.CreateAccount = true;
        PlayFabClientAPI.LoginWithFacebook(request, RequestPhotonToken, OnPlayFabError);
    }
Exemplo n.º 3
0
 public static AccessToken Create(Facebook.Unity.AccessToken token)
 {
     if (token == null)
     {
         return(null);
     }
     else
     {
         AccessToken t = new AccessToken();
         t.tokenString    = token.TokenString;
         t.expirationTime = token.ExpirationTime;
         t.permissions    = token.Permissions;
         t.userId         = token.UserId;
         t.lastRefresh    = token.LastRefresh;
         return(t);
     }
 }
Exemplo n.º 4
0
 public static void Init(Facebook.Unity.AccessToken aToken)
 {
     if (_userData == null)
     {
         _userData                  = UserData.CreateInstance <UserData>();
         _userData._userId          = aToken.UserId;
         _userData._userAccessToken = aToken.TokenString;
         PlayerPrefs.SetString("user_local_ID", _userData._userId);
         PlayerPrefs.SetString("user_local_token", _userData._userAccessToken);
         Debug.Log("UserData: Create UserData");
         FacebookAPI.GetUserProfile(_userData._userId, result =>
         {
             _userData._userName = result["name"];
             PlayerPrefs.SetString("gender", result["gender"]);
         });
     }
 }
Exemplo n.º 5
0
    /// <summary>
    /// Funkcija koja linkuje facebook nalog (fb id) sa korisnickim nalogom na Firebase-u
    /// Uz anonimnog korisnika se dodaju novi kredencijali (fb) i svako sledece pozivanje ove funkcije nece uspeti
    /// jer je fbid vec linkovan.
    /// </summary>

    public void ConnectWithFacebook(Facebook.Unity.AccessToken accessToken)
    {
        Firebase.Auth.Credential credential =
            Firebase.Auth.FacebookAuthProvider.GetCredential(accessToken.TokenString);

        /// <summary>
        /// Pokusava se linkovanje sa fejsbukom
        /// </summary>
        auth.CurrentUser.LinkWithCredentialAsync(credential).ContinueWith(task => {
            if (task.IsCanceled)
            {
                Debug.LogError("LinkWithCredentialAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                //Nalog je vec linkovan
                //Treba ucitati podatke tog usera
                Debug.LogError("LinkWithCredentialAsync encountered an error: " + task.Exception);
                SignInWithFacebook(accessToken.TokenString);
                return;
            }

            /// <summary>
            /// Uspelo je linkovanje
            /// </summary>
            Firebase.Auth.FirebaseUser newUser = task.Result;
            Debug.LogFormat("Credentials successfully linked to Firebase user: {0} ({1})",
                            newUser.DisplayName, newUser.UserId);

            Debug.Log("Old user id : " + user.UserId);
            Debug.Log("New user id : " + newUser.UserId);

            //newUser ostaje isti ako se uspesno linkuje
            user            = newUser;
            App.player.uid  = user.UserId;
            App.player.fbid = accessToken.UserId;
            Debug.Log("Player fbid : " + App.player.fbid);

            /// <summary>
            /// Pamtimo stare podatke sa novim id-jem na server
            /// </summary>
            Save();
        });
    }
Exemplo n.º 6
0
 /**
  * Callback function when the api has been processed
  **/
 private void FBAuthCallback(ILoginResult result)
 {
     if (FB.IsLoggedIn)
     {
         this.loggedIn    = true;
         this.accessToken = AccessToken.CurrentAccessToken;
         credentials      = FacebookAuthProvider.GetCredential(this.accessToken.TokenString);
         print(credentials);
         datahandler.SetIsLoggedIn(true);
         loginOutbtn.GetComponentInChildren <Text>().text = "Logout";
         FirebaseLogin();
         FB.API("me?fields=name", Facebook.Unity.HttpMethod.GET, GetFacebookData);
     }
     else
     {
         this.loggedIn = false;
         loginOutbtn.GetComponentInChildren <Text>().text = "Login";
         Debug.Log("User cancelled login");
         datahandler.SetIsLoggedIn(false);
     }
 }
        /// <summary>
        /// Sign in request
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public UnityTask FacebookConnect(AccessToken token)
        {
            var task = new UnityTask { Strategy = TaskStrategy.Custom };

            FacebookConnect(token, task.FromResponse());

            return task;
        }
 /// <summary>
 /// Sign in request
 /// </summary>
 /// <returns></returns>
 public void FacebookConnect(AccessToken token, Action<Response> callback)
 {
     HttpPostAsync<AccountDetails>("FacebookConnect", new AccountFacebookConnect
     {
         AccessToken = token.TokenString,
     },
     response =>
     {
         if (response.IsSuccess && response.Result != null)
         {
             FBToken = token;
             ReadDetails(response.Result);
         }
     });
 }
        IEnumerator ConnectFacebookAsync2(AccessToken accessToken)
        {
            var task = AccountService.Instance.FacebookConnect(accessToken);

            yield return task;

            if (task.IsFaulted)
            {
                Debug.LogException(task.Exception);
            }
            else
            {
                Debug.Log("Facebook Connected");
            }
        }
Exemplo n.º 10
0
 internal LoginResult(string response, AccessToken token = null) : base(response)
 {
     this.AccessToken = token;
 }
Exemplo n.º 11
0
 public SA_AccessToken(FB_Plugin.AccessToken accessToken)
 {
     m_accessToken = accessToken;
 }
Exemplo n.º 12
0
 internal LoginResult(string response, AccessToken token = null)
     : base(response)
 {
     this.AccessToken = token;
 }