public void ReceiveNewTokenMessage(string message) { //#if UNITY_ANDROID || UNITY_EDITOR||UNITY_WP8||UNITY_IOS string[] token = message.Split('#'); TokenInfo ti=new TokenInfo(); ti.access_token = token [0]; ti.tokenRecievedTime = DateTime.Now; ti.expires_in = int.Parse(token [2])==0?999999:int.Parse(token [2]); ti.user_id = token [3]; vkapi.onReceiveNewToken (ti); //#endif }
public TokenInfo parseToenFromString() { var authUrl=myScript.auth_url; string[] firstsplit=authUrl.Split('#'); string[] secondsplit=firstsplit[1].Split('&'); var tokeninfo = new Dictionary<string,string> (); foreach (var secondsplitemevent in secondsplit) { string[] thirdsplit=secondsplitemevent.Split('='); tokeninfo.Add(thirdsplit[0],thirdsplit[1]); } TokenInfo ti1=new TokenInfo(); int outvar = 99999999; ti1.access_token = tokeninfo ["access_token"]; ti1.expires_in = int.TryParse (tokeninfo ["expires_in"], out outvar) ? outvar : outvar; if(outvar==0) { ti1.expires_in=9999999; } ti1.user_id = tokeninfo ["user_id"]; ti1.tokenRecievedTime = DateTime.Now; return ti1; }
void Start() { #if !UNITY_EDITOR UseManualData=false; #else UseManualData=true; #endif if (!UseManualData) { currentToken = new TokenInfo{ access_token=PlayerPrefs.GetString ("access_token", ""), expires_in=PlayerPrefs.GetInt ("expires_in", 0), user_id=PlayerPrefs.GetString ("user_id", "") }; DateTime.TryParse (PlayerPrefs.GetString ("tokenRecievedTime", "1/1/1990"), out currentToken.tokenRecievedTime); } else { SetUpEditor(); currentToken = new TokenInfo { access_token=access_token_manual, tokenRecievedTime=DateTime.Now, expires_in=999999, user_id=user_id_manual }; } if (isValidToken (currentToken)) { isUserLoggedIn = true; } else { isUserLoggedIn = false; } }
public void onReceiveNewToken(TokenInfo e) { currentToken = e; PlayerPrefs.SetString ("access_token", e.access_token); PlayerPrefs.SetInt ("expires_in", e.expires_in); PlayerPrefs.SetString ("tokenRecievedTime", e.tokenRecievedTime.ToString()); PlayerPrefs.SetString ("user_id", e.user_id); if(ReceivedNewToken!=null) ReceivedNewToken (this,e); onLoggedIn (); Debug.Log("New token is"+e.access_token); }
public bool isValidToken(TokenInfo ti) { var isvalid=currentToken.tokenRecievedTime.AddSeconds(currentToken.expires_in)>DateTime.Now?true:false; return isvalid; }