/// <summary> /// password flow授权解析token信息 /// </summary> /// <param name="result">数据</param> private void DecoderTokenInfo(string result) { AccessToken token = new AccessToken(); try { token = (AccessToken)JsonUtility.DeserializeObj( new MemoryStream(Encoding.UTF8.GetBytes(result)), typeof(AccessToken)); } catch { NotifyError("encoding error"); return; } tokenInfo = new TokenInfo(); tokenInfo.access_token = token.access_token; tokenInfo.expires_in = DateTime.Now.AddSeconds(Int32.Parse(token.expires_in)); tokenInfo.refresh_token = token.refresh_token; tokenInfo.scope = token.scope; currentState = TLoginState.KGetUserInfo; RenrenSDK.RenrenInfo.SetTokenInfo(tokenInfo); GetCurrentUserInfo(); }
/// <summary> /// 客户端授权保存token信息 /// </summary> /// <param name="authorizationCode"></param> public void SaveAccessToken(string accessToken, string expiresIn) { tokenInfo = new TokenInfo(); tokenInfo.access_token = accessToken; tokenInfo.expires_in = DateTime.Now.AddSeconds(Int32.Parse(expiresIn)); currentState = TLoginState.KGetUserInfo; RenrenSDK.RenrenInfo.SetTokenInfo(tokenInfo); GetCurrentUserInfo(); }
/// <summary> /// 登录 /// </summary> /// <param name="username">用户名</param> /// <param name="password">密码</param> public void LogIn(string username, string password, List <string> scope) { if (username == null || password == null) { NotifyError("username or password is null"); return; } if (ConstantValue.ApiKey == null || ConstantValue.SecretKey == null) { NotifyError("we need apiKey and SecretKey"); return; } currentState = TLoginState.KGetToken; loginRequest.LogIn(username, password, scope, DownloadStringCompleted); }
/// <summary> /// 获取当前用户信息 /// </summary> private void GetCurrentUserInfo() { GetUserInfoRequest getcuruserinfoRequest = new GetUserInfoRequest(); List <string> scope = new List <string>(); scope.Add("uid"); scope.Add("name"); scope.Add("sex"); scope.Add("star"); scope.Add("zidou"); scope.Add("vip"); scope.Add("birthday"); scope.Add("email_hash"); scope.Add("tinyurl"); scope.Add("headurl"); scope.Add("mainurl"); scope.Add("hometown_location"); scope.Add("work_history"); scope.Add("university_history"); currentState = TLoginState.KGetUserInfo; getcuruserinfoRequest.GetUserInfo(scope, DownloadStringCompleted); }
/// <summary> /// 登录 /// </summary> /// <param name="username">用户名</param> /// <param name="password">密码</param> public void LogIn(string username, string password, List<string> scope ) { if (username == null || password == null) { NotifyError("username or password is null"); return; } if (ConstantValue.ApiKey == null || ConstantValue.SecretKey == null) { NotifyError("we need apiKey and SecretKey"); return; } currentState = TLoginState.KGetToken; loginRequest.LogIn(username, password, scope, DownloadStringCompleted); }
/// <summary> /// 获取当前用户信息 /// </summary> private void GetCurrentUserInfo() { GetUserInfoRequest getcuruserinfoRequest = new GetUserInfoRequest(); List<string> scope = new List<string>(); scope.Add("uid"); scope.Add("name"); scope.Add("sex"); scope.Add("star"); scope.Add("zidou"); scope.Add("vip"); scope.Add("birthday"); scope.Add("email_hash"); scope.Add("tinyurl"); scope.Add("headurl"); scope.Add("mainurl"); scope.Add("hometown_location"); scope.Add("work_history"); scope.Add("university_history"); currentState = TLoginState.KGetUserInfo; getcuruserinfoRequest.GetUserInfo(scope, DownloadStringCompleted); }