Exemplo n.º 1
0
        //3.获取用户信息
        #region 请求参数

        /*
         * 请求参数
         * 基于https调用Open API时需要传递的系统级输入参数:
         *
         * 参数名	参数类型	是否必需	描述
         * access_token	string	是	授权码,应用访问百度的任何Restful Open API都必须出具授权码以表明其是一个合法第三方。其值必须是通过OAuth2.0协议换取access token时所拿到的access_token参数值。
         * ************************************
         *返回字段说明
         * {
         * "login": "******",
         * "id": 1,
         * "avatar_url": "https://github.com/images/error/octocat_happy.gif",
         * "gravatar_id": "",
         * "url": "https://api.github.com/users/octocat",
         * "html_url": "https://github.com/octocat",
         * "followers_url": "https://api.github.com/users/octocat/followers",
         * "following_url": "https://api.github.com/users/octocat/following{/other_user}",
         * "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
         * "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
         * "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
         * "organizations_url": "https://api.github.com/users/octocat/orgs",
         * "repos_url": "https://api.github.com/users/octocat/repos",
         * "events_url": "https://api.github.com/users/octocat/events{/privacy}",
         * "received_events_url": "https://api.github.com/users/octocat/received_events",
         * "type": "User",
         * "site_admin": false,
         * "name": "monalisa octocat",
         * "company": "GitHub",
         * "blog": "https://github.com/blog",
         * "location": "San Francisco",
         * "email": "*****@*****.**",
         * "hireable": false,
         * "bio": "There once was...",
         * "public_repos": 2,
         * "public_gists": 1,
         * "followers": 20,
         * "following": 0,
         * "created_at": "2008-01-14T04:33:35Z",
         * "updated_at": "2008-01-14T04:33:35Z",
         * "total_private_repos": 100,
         * "owned_private_repos": 100,
         * "private_gists": 81,
         * "disk_usage": 10000,
         * "collaborators": 8,
         * "plan": {
         *  "name": "Medium",
         *  "space": 400,
         *  "private_repos": 20,
         *  "collaborators": 0
         * }
         * }
         */
        #endregion

        #region 获取用户基本信息
        /// <summary>
        /// 获取用户基本信息
        /// </summary>
        /// <returns></returns>
        public Dictionary <string, object> GetUserBaseInfo()
        {
            try
            {
                Dictionary <string, object> result = Conf.GetDictionary(UserBaseInfoUrl, Access_Token);
                //string json = result["plan"].ToString();
                //Dictionary<string, object> plan = JsonHelper.Deserialize<Dictionary<string, object>>(json);
                if (result != null && result.Count > 0)
                {
                    this.UserBaseInfo = new GitHubUserInfo()
                    {
                        login               = result["login"].ToString(),
                        id                  = result["id"].ToString(),
                        avatar_url          = result["avatar_url"].ToString(),
                        gravatar_id         = result["gravatar_id"].ToString(),
                        url                 = result["url"].ToString(),
                        html_url            = result["html_url"].ToString(),
                        followers_url       = result["followers_url"].ToString(),
                        following_url       = result["following_url"].ToString(),
                        gists_url           = result["gists_url"].ToString(),
                        starred_url         = result["starred_url"].ToString(),
                        subscriptions_url   = result["subscriptions_url"].ToString(),
                        organizations_url   = result["organizations_url"].ToString(),
                        repos_url           = result["repos_url"].ToString(),
                        events_url          = result["events_url"].ToString(),
                        received_events_url = result["received_events_url"].ToString(),
                        type                = result["type"].ToString(),
                        site_admin          = result["site_admin"].ToString(),
                        name                = result["name"].ToString(),
                        company             = result["company"].ToString(),
                        blog                = result["blog"].ToString(),
                        location            = result["location"].ToString(),
                        email               = result["email"].ToString(),
                        hireable            = result["hireable"].ToString(),
                        bio                 = result["bio"] != null ? result["bio"].ToString(): null,
                        public_repos        = result["public_repos"].ToString(),
                        public_gists        = result["public_gists"].ToString(),
                        followers           = result["followers"].ToString(),
                        following           = result["following"].ToString(),
                        created_at          = result["created_at"].ToString(),
                        updated_at          = result["updated_at"].ToString(),
                        //total_private_repos = result["total_private_repos"].ToString(),
                        //owned_private_repos = result["owned_private_repos"].ToString(),
                        //private_gists = result["private_gists"].ToString(),
                        //disk_usage = result["disk_usage"].ToString(),
                        //collaborators = result["collaborators"].ToString(),
                        //plan_name = plan["name"].ToString(),
                        //plan_space = plan["space"].ToString(),
                        //plan_private_repos = plan["private_repos"].ToString(),
                        //plan_collaborators = plan["collaborators"].ToString()
                    };
                }
                return(result);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        //3.获取用户信息
        #region 请求参数

        /*
         * 请求参数
         * 基于https调用Open API时需要传递的系统级输入参数:
         *
         * 参数名	参数类型	是否必需	描述
         * access_token	string	是	授权码,应用访问百度的任何Restful Open API都必须出具授权码以表明其是一个合法第三方。其值必须是通过OAuth2.0协议换取access token时所拿到的access_token参数值。
         * ************************************
         *返回字段说明
         * "id": "1462702590710348",
         * "first_name": "Seay",
         * "gender": "male",
         * "last_name": "Xu",
         * "link": "https://www.facebook.com/app_scoped_user_id/1462702590710348/",
         * "locale": "zh_CN",
         * "name": "Seay Xu",
         * "timezone": 8,
         * "updated_time": "2015-06-30T05:50:43+0000",
         * "verified": true
         */
        #endregion

        #region 获取用户基本信息
        /// <summary>
        /// 获取用户基本信息
        /// </summary>
        /// <returns></returns>
        public Dictionary <string, object> GetUserBaseInfo()
        {
            try
            {
                Dictionary <string, object> result = Conf.GetDictionary(UserBaseInfoUrl, Access_Token);
                if (result != null && result.Count > 0)
                {
                    this.UserBaseInfo = new GitHubUserInfo()
                    {
                        login               = result["login"].ToString(),
                        id                  = result["id"].ToString(),
                        avatar_url          = result["avatar_url"].ToString(),
                        gravatar_id         = result["gravatar_id"].ToString(),
                        url                 = result["url"].ToString(),
                        html_url            = result["html_url"].ToString(),
                        followers_url       = result["followers_url"].ToString(),
                        following_url       = result["following_url"].ToString(),
                        gists_url           = result["gists_url"].ToString(),
                        starred_url         = result["starred_url"].ToString(),
                        subscriptions_url   = result["subscriptions_url"].ToString(),
                        organizations_url   = result["organizations_url"].ToString(),
                        repos_url           = result["repos_url"].ToString(),
                        events_url          = result["events_url"].ToString(),
                        received_events_url = result["received_events_url"].ToString(),
                        type                = result["type"].ToString(),
                        site_admin          = result["site_admin"].ToString(),
                        name                = result["name"].ToString(),
                        company             = result["company"].ToString(),
                        blog                = result["blog"].ToString(),
                        location            = result["location"].ToString(),
                        email               = result["email"].ToString(),
                        hireable            = result["hireable"].ToString(),
                        bio                 = result["bio"] != null ? result["bio"].ToString() : null,
                        public_repos        = result["public_repos"].ToString(),
                        public_gists        = result["public_gists"].ToString(),
                        followers           = result["followers"].ToString(),
                        following           = result["following"].ToString(),
                        created_at          = result["created_at"].ToString(),
                        updated_at          = result["updated_at"].ToString()
                    };
                }
                return(result);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult <User> > GetUserInfo([FromQuery] string code)
        {
            User user = await GetUserWithToken(code);

            if (user == default(User))
            {
                return(default(User));
            }
            GitHubUserInfo userInfo = await GetGitHubUserInfo(user.BearerToken);

            if (userInfo == default(GitHubUserInfo))
            {
                return(default(User));
            }
            user.Username = userInfo.Login;
            return(user);
        }