Exemplo n.º 1
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="accessTokenObject"></param>
        /// <returns></returns>
        public override async Task <OAuthUserInfo> GetUserInfo(AccessTokenObject accessTokenObject)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                //3、获取用户信息
                var userInfo = await httpClient.GetStringAsync("https://api.weibo.com/2/users/show.json?access_token=" + accessTokenObject.AccessToken + "&uid=" + accessTokenObject.UserId);

                //授权用户的UID,本字段只是为了方便开发者,减少一次user/show接口调用而返回的
                //,第三方应用不能用此字段作为用户登录状态的识别,只有access_token才是用户授权的唯一票据。
                var dynamicObject = JsonConvert.DeserializeObject <dynamic>(userInfo);
                var user          = new OAuthUserInfo()
                {
                    Id     = accessTokenObject.UserId,
                    Name   = dynamicObject.name.ToString(),
                    Gender = dynamicObject.gender.ToString() == "m" ? true : false,
                    ImgUrl = dynamicObject.avatar_hd.ToString()
                };
                return(user);
            }
        }