예제 #1
0
        public static async Task <Info> getInfo()
        {
            Info       info   = new Info();
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = System.Net.Http.Headers.AuthenticationHeaderValue.Parse("Bearer " + await oAuth.GetAccessToken());
            client.DefaultRequestHeaders.Add("User-Agent", "google-oauth-playground");

            string      postData = "{\"allowNonGooglePlusUsers\":false}";
            HttpContent content  = new StringContent(postData);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage response = await client.PostAsync(new Uri(LOAD_SOCIAL_API), content);

            if (response.IsSuccessStatusCode == true)
            {
                var result = JObject.Parse(await response.Content.ReadAsStringAsync());
                info.avatar = Other.parseLink((string)result["user"]["info"]["photoUrl"]);
                info.name   = (string)result["user"]["info"]["displayName"];
                info.userID = (string)result["user"]["info"]["obfuscatedGaiaId"];
                return(info);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
파일: Users.cs 프로젝트: borewicz/gplus
        private static User _parseUser(JObject data)
        {
            User    user     = new User();
            JObject content  = (JObject)data["profile"]["content"];
            JObject userData = (JObject)data["profile"]["user"];

            user.userId    = (string)data["profile"]["obfuscatedGaiaId"];
            user.name      = (string)data["profile"]["displayName"];
            user.given     = (string)userData["name"]["given"];
            user.family    = (string)userData["name"]["family"];
            user.avatarUrl = Other.parseLink((string)content["photoUrl"]);
            user.gender    = (string)userData["gender"]["value"];

            if (userData["otherNames"] != null)
            {
                foreach (var nick in (JArray)userData["otherNames"]["name"])
                {
                    user.nicks.Add((string)nick["value"]);
                }
            }

            user.occupation     = (string)userData["occupation"]["value"];
            user.skills         = (string)userData["skills"]["value"];
            user.braggingRights = (string)userData["braggingRights"]["value"];
            user.tagline        = (string)content["tagLine"]["value"];
            user.intro          = (string)content["introduction"]["value"];

            if (userData["employments"] != null)
            {
                foreach (var employment in userData["employments"]["employment"])
                {
                    User.HistoryElement element = new User.HistoryElement();
                    element.name  = (string)employment["employer"];
                    element.title = (string)employment["title"];
                    if (employment["dateInfo"] != null)
                    {
                        if (employment["dateInfo"]["end"] != null)
                        {
                            element.end = //((int)employment["dateInfo"]["end"]["day"]).ToString() + "-" +
                                          //((int)employment["dateInfo"]["end"]["month"]).ToString() + "-" +
                                          ((int)employment["dateInfo"]["end"]["year"]).ToString();
                        }
                        if (employment["dateInfo"]["start"] != null)
                        {
                            element.start = //((int)employment["dateInfo"]["start"]["day"]).ToString() + "-" +
                                            //((int)employment["dateInfo"]["start"]["month"]).ToString() + "-" +
                                            ((int)employment["dateInfo"]["start"]["year"]).ToString();
                        }
                    }
                    element.description = (string)employment["description"];
                    user.employment.Add(element);
                }
            }

            if (userData["educations"] != null)
            {
                foreach (var school in userData["educations"]["education"])
                {
                    User.HistoryElement element = new User.HistoryElement();
                    element.name        = (string)school["school"];
                    element.title       = (string)school["majorConcentration"];
                    element.description = (string)school["description"];

                    if (school["dateInfo"] != null)
                    {
                        if (school["dateInfo"]["end"] != null)
                        {
                            element.end = //((int)school["dateInfo"]["end"]["day"]).ToString() + "-" +
                                          //((int)school["dateInfo"]["end"]["month"]).ToString() + "-" +
                                          ((int)school["dateInfo"]["end"]["year"]).ToString();
                        }
                        if (school["dateInfo"]["start"] != null)
                        {
                            element.start = //((int)school["dateInfo"]["start"]["day"]).ToString() + "-" +
                                            //((int)school["dateInfo"]["start"]["month"]).ToString() + "-" +
                                            ((int)school["dateInfo"]["start"]["year"]).ToString();
                        }
                    }
                    user.education.Add(element);
                }
            }

            if (userData["locations"] != null)
            {
                user.mapUrl          = Other.parseLink((string)userData["locations"]["locationMapUrl"]);
                user.currentLocation = (string)userData["locations"]["currentLocation"];
                if (userData["locations"]["otherLocation"] != null)
                {
                    foreach (var other in userData["locations"]["otherLocation"])
                    {
                        user.olderLocation.Add((string)other);
                    }
                }
            }

            if (content["links"] != null)
            {
                foreach (var l in content["links"]["link"])
                {
                    User.Link link = new User.Link();
                    link.link       = (string)(l["normalizedUri"].First());
                    link.faviconUrl = Other.parseLink((string)l["faviconImgUrl"]);
                    link.label      = (string)l["label"];
                    link.rel        = (string)l["rel"];
                    //link.type = (string)l[]
                    switch ((string)l["type"])
                    {
                    case "ME": user.links.Add(link);
                        break;

                    case "CONTRIBUTOR": user.contributeTo.Add(link);
                        break;

                    case "OTHER": user.otherProfiles.Add(link);
                        break;
                    }
                    user.otherProfiles.Add(link);
                }
            }

            user.backgroundUrl = (string)content["scrapbook"]["defaultCoverPhotoUrl"];

            if (content["contacts"] != null)
            {
                if (content["contacts"]["phone"] != null)
                {
                    foreach (var item in content["contacts"]["phone"])
                    {
                        User.Contact contact = new User.Contact();
                        contact.value = (string)item["value"];
                        contact.type  = (string)item["type"];
                        user.phone.Add(contact);
                    }
                }

                if (content["contacts"]["address"] != null)
                {
                    foreach (var item in content["contacts"]["address"])
                    {
                        User.Contact address = new User.Contact();
                        address.value = (string)item["value"];
                        user.address.Add(address);
                    }
                }
                if (content["contacts"]["instantMessage"] != null)
                {
                    foreach (var item in content["contacts"]["instantMessage"])
                    {
                        User.Contact im = new User.Contact();
                        im.value = (string)item["value"];
                        //contact.type = (string)item["type"];
                        im.protocol = (string)item["protocol"];
                        user.IM.Add(im);
                    }
                }
            }

            user.relationship = (string)userData["relationshipStatus"]["value"];

            if (userData["relationshipInterests"]["interest"] != null)
            {
                foreach (var interest in userData["relationshipInterests"]["interest"])
                {
                    user.lookingFor.Add((string)interest["value"]);
                }
            }
            return(user);
        }