public static async Task <Ravka.Helpers.Outcomes.ReturnClass <UserInfo> > GetUserInfoAsync(UserCredential credential) { var r = new UserInfo(); var index = 0; var hasValues = false; var useNewerVersion = true; var partsOfProfileCount = new SortedList <Ravka.Helpers.Globals.Users.PartOfProfile, int>(); if (useNewerVersion) { // Create the service. var peopleService = new Google.Apis.PeopleService.v1.PeopleServiceService //var peopleService = new PeopleService (new BaseClientService.Initializer { HttpClientInitializer = credential // ApplicationName = "APP_NAME", }); var peopleRequest = peopleService.People.Get("people/me"); peopleRequest.PersonFields = "locations,names,birthdays,genders,phoneNumbers,addresses,emailAddresses"; // person.emailAddresses, //peopleRequest.RequestMaskIncludeField = "person.genders,person.phonenumbers,person.names,person.birthdays,person.addresses"; var myInfo = await peopleRequest.ExecuteAsync(); if (myInfo != null) { { var collection = myInfo.Addresses; if (collection != null) { var count = collection.CleanCount(); partsOfProfileCount.Add(Ravka.Helpers.Globals.Users.PartOfProfile.Address, count); if (index < count) { var m = collection[count]; if (m != null) { r.Location.LocationText = m.FormattedValue; r.Location.LocationType = m.FormattedType; hasValues = true; } } } } { var collection = myInfo.Birthdays; if (collection != null) { var count = collection.CleanCount(); partsOfProfileCount.Add(Ravka.Helpers.Globals.Users.PartOfProfile.Age, count); if (index < count) { var m = collection[count]; if (m.Date != null) { var b = new Ravka.Helpers.Dtos.UserInfo.BirthDayCxt( Ravka.Helpers.Dates.Birthday.BirthDatePartsToDateTimeUtc (m.Date.Year ?? Ravka.Helpers.Dates.SqlMinDate.Year, m.Date.Month ?? 1, m.Date.Year ?? 1)); r.Birthday = Ravka.Helpers.Dates.Birthday.BirthDayCtxToCoded(b); hasValues = true; } } } } { var collection = myInfo.EmailAddresses; if (collection != null) { var count = collection.CleanCount(); partsOfProfileCount.Add(Ravka.Helpers.Globals.Users.PartOfProfile.Email, count); if (index < count) { var m = collection[count]; if (m.Value.IsNullOrEmpty() == false) { r.Email = m.Value.ToCleanString(); hasValues = true; } } } } { var collection = myInfo.Genders; if (collection != null) { var count = collection.CleanCount(); partsOfProfileCount.Add(Ravka.Helpers.Globals.Users.PartOfProfile.Gender, count); if (index < count) { var m = collection[count]; if (m.Value.IsNullOrEmpty() == false) { r.Gender = m.Value; hasValues = true; } } } } { var collection = myInfo.Names; if (collection != null) { var count = collection.CleanCount(); partsOfProfileCount.Add(Ravka.Helpers.Globals.Users.PartOfProfile.Name, count); if (index < count) { var m = collection[count]; if (m != null) { r.FirstName = m.GivenName; r.LastName = m.FamilyName; hasValues = true; } } } } r.UserReferenceId = myInfo.ResourceName; } Console.WriteLine("done myinfo2"); } return(new Ravka.Helpers.Outcomes.ReturnClass <UserInfo>(hasValues) { Value = hasValues ? r : null }); /* else * { * var peopleService = new Google.Apis.People.v1.PeopleService(new BaseClientService.Initializer * * { * HttpClientInitializer = credential * // ApplicationName = "APP_NAME", * }); * * var peopleRequest = peopleService.People.Get("people/me"); * peopleRequest.RequestMaskIncludeField = "person.names,person.emailAddresses,person.birthdays,person.genders,person.addresses,person.phoneNumbers"; // * var myInfo = await peopleRequest.ExecuteAsync(); * myInfo = new Google.Apis.People.v1.Data.Person(); // Google.Apis.People.v1.Data * Console.WriteLine("done myinfo2"); * } */ }
private UserInfo GooglePersonObjectToUserInfo(Google.Apis.PeopleService.v1.Data.Person myInfo) { var r = new UserInfo(); if (myInfo != null) { var index = 0; var hasValues = false; var useNewerVersion = true; var partsOfProfileCount = new SortedList <Ravka.Helpers.Globals.Users.PartOfProfile, int>(); { var collection = myInfo.Addresses; if (collection != null) { var count = collection.CleanCount(); partsOfProfileCount.Add(Ravka.Helpers.Globals.Users.PartOfProfile.Address, count); if (index < count) { var m = collection[index]; if (m != null) { r.Location.LocationText = m.FormattedValue; r.Location.LocationType = m.FormattedType; hasValues = true; } } } } { var collection = myInfo.Birthdays; if (collection != null) { var count = collection.CleanCount(); partsOfProfileCount.Add(Ravka.Helpers.Globals.Users.PartOfProfile.Age, count); if (index < count) { var m = collection[index]; if (m.Date != null) { var b = new Ravka.Helpers.Dtos.UserInfo.BirthDayCxt( Ravka.Helpers.Dates.Birthday.BirthDatePartsToDateTimeUtc (m.Date.Year ?? Ravka.Helpers.Dates.SqlMinDate.Year, m.Date.Month ?? 1, m.Date.Day ?? 1)); r.Birthday = Ravka.Helpers.Dates.Birthday.BirthDayCtxToCoded(b); hasValues = true; } } } } { var collection = myInfo.EmailAddresses; if (collection != null) { var count = collection.CleanCount(); partsOfProfileCount.Add(Ravka.Helpers.Globals.Users.PartOfProfile.Email, count); if (index < count) { var m = collection[index]; if (m.Value.IsNullOrEmpty() == false) { r.Email = m.Value.ToCleanString(); hasValues = true; } } } } { var collection = myInfo.Genders; if (collection != null) { var count = collection.CleanCount(); partsOfProfileCount.Add(Ravka.Helpers.Globals.Users.PartOfProfile.Gender, count); if (index < count) { var m = collection[index]; if (m.Value.IsNullOrEmpty() == false) { r.Gender = m.Value; hasValues = true; } } } } { var collection = myInfo.Names; if (collection != null) { var count = collection.CleanCount(); partsOfProfileCount.Add(Ravka.Helpers.Globals.Users.PartOfProfile.Name, count); if (index < count) { var m = collection[index]; if (m != null) { r.FirstName = m.GivenName; r.LastName = m.FamilyName; hasValues = true; } } } } r.UserReferenceId = myInfo.ResourceName; } return(r); }