public void Init() { state = FacebookState.FB_INIT; //Initialize() // SPFacebook.instance.addEventListener(FacebookEvents.FACEBOOK_INITED, OnInit); SPFacebook.OnInitCompleteAction += OnInit; SPFacebook.OnFocusChangedAction += OnFocusChanged; //Login() // SPFacebook.instance.addEventListener(FacebookEvents.AUTHENTICATION_SUCCEEDED, OnAuth); // SPFacebook.instance.addEventListener(FacebookEvents.AUTHENTICATION_FAILED,OnFailedAuth); SPFacebook.OnAuthCompleteAction += OnAuth; //LoadUserData() // SPFacebook.instance.addEventListener(FacebookEvents.USER_DATA_LOADED, OnUserDataLoaded); // SPFacebook.instance.addEventListener(FacebookEvents.USER_DATA_FAILED_TO_LOAD, OnUserDataLoadFailed); SPFacebook.OnUserDataRequestCompleteAction += OnUserDataLoaded; // SPFacebook.instance.addEventListener(FacebookEvents.FRIENDS_DATA_LOADED, OnFriendLoaded); // SPFacebook.instance.addEventListener(FacebookEvents.FRIENDS_FAILED_TO_LOAD, OnFriendLoadedFailed); SPFacebook.OnFriendsDataRequestCompleteAction += OnFriendLoaded; // SPFacebook.instance.addEventListener(FacebookEvents.POST_SUCCEEDED, OnPost); // SPFacebook.instance.addEventListener(FacebookEvents.POST_FAILED, OnPostFailed); SPFacebook.OnPostingCompleteAction += OnPost; SPFacebook.instance.Init(); }
/// <summary> /// On Connected /// </summary> /// <param name="task"></param> private static void OnConnectReceived(Task <Object> task) { try { _user = new User(task.Result.ToString()); // Load facebook achievements and progress PlayerProgress.Load(_user.Id); // Set Authorized Connection |= FacebookState.Authorized; //string profilePictureUrl = String.Format("/{0}/picture?type={1}", _user.Id, "square"); } catch (AggregateException aex) { aex.Handle((e) => { if (e is FacebookOAuthException) { } return(false); }); } }
/// <summary> /// Setups the application link. /// </summary> public static void Setup() { _app = new FacebookClient(); _app.AppId = "223453524434397"; _app.AppSecret = "3b6769b53e52b0d122d2572950d770bd"; dynamic parameters = new ExpandoObject(); parameters.client_id = _app.AppId; parameters.client_secret = _app.AppSecret; parameters.grant_type = "client_credentials"; Task <Object> connect = _app.GetTaskAsync("https://graph.facebook.com/oauth/access_token", parameters); connect.ContinueWith(task => { try { // Save the access token _app.AccessToken = JObject.Parse(task.Result.ToString()).Value <String>("access_token"); Connection |= FacebookState.Connected; } catch (AggregateException aex) { aex.Handle(e => { if (e is FacebookOAuthException) { } return(true); }); } }); }
void FacebookAPICallback(IResult result) { if (result.Error == null) { var dict = result.ResultDictionary; string userName = dict["name"].ToString(); string id = dict["id"].ToString(); string first_name = dict["first_name"].ToString(); string email = dict["email"].ToString(); string AccessToken = Facebook.Unity.AccessToken.CurrentAccessToken.TokenString; Debug.Log("FaceBook UserName ---->" + userName); Debug.Log("FaceBook id -------->" + id); Debug.Log("Facebook AccessToken ----->" + AccessToken); Debug.Log("Facebook email ----->" + email); switch (curState) { case FacebookState.LoginSate: { curState = FacebookState.InitState; DestroyGameObject(); } break; default: break; } } }
/// <summary> /// Setups the application link. /// </summary> public static void Setup() { _app = new FacebookClient(); _app.AppId = "223453524434397"; _app.AppSecret = "3b6769b53e52b0d122d2572950d770bd"; dynamic parameters = new ExpandoObject(); parameters.client_id = _app.AppId; parameters.client_secret = _app.AppSecret; parameters.grant_type = "client_credentials"; Task<Object> connect = _app.GetTaskAsync("https://graph.facebook.com/oauth/access_token", parameters); connect.ContinueWith(task => { try { // Save the access token _app.AccessToken = JObject.Parse(task.Result.ToString()).Value<String>("access_token"); Connection |= FacebookState.Connected; } catch (AggregateException aex) { aex.Handle(e => { if (e is FacebookOAuthException) { } return true; }); } }); }
void FacebookLoginCallBack(IResult result) { if (result.Error != null) { curState = FacebookState.InitState; DestroyGameObject(); } else if (!FB.IsLoggedIn) { curState = FacebookState.InitState; DestroyGameObject(); } else { FB.API("me?fields=id,name,email,first_name", HttpMethod.GET, FacebookAPICallback); } }
void FacebookAPICallback(IResult result) { if (result.Error == null) { var dict = result.ResultDictionary; string userName = dict ["name"].ToString(); string id = dict ["id"].ToString(); string first_name = dict ["first_name"].ToString(); string email = dict ["email"].ToString(); string AccessToken = Facebook.Unity.AccessToken.CurrentAccessToken.TokenString; Debug.Log("FaceBook UserName ---->" + userName); Debug.Log("FaceBook id -------->" + id); Debug.Log("Facebook AccessToken ----->" + AccessToken); Debug.Log("Facebook email ----->" + email); AppManager.Instance.username = userName; UserLoginWithFBAPICalls(userName, id, email, first_name); switch (curState) { case FacebookState.LoginSate: { curState = FacebookState.InitState; DestroyGameObject(); } break; default: break; } } else { AppManager.Instance.ShowMessage(Global.facebookLoginWrong, PopUpMessage.eMessageType.Error); } }
/// <summary> /// On Connected /// </summary> /// <param name="task"></param> private static void OnConnectReceived(Task<Object> task) { try { _user = new User(task.Result.ToString()); // Load facebook achievements and progress PlayerProgress.Load(_user.Id); // Set Authorized Connection |= FacebookState.Authorized; //string profilePictureUrl = String.Format("/{0}/picture?type={1}", _user.Id, "square"); } catch (AggregateException aex) { aex.Handle((e) => { if (e is FacebookOAuthException) { } return false; }); } }