public async Task LoadData() { try { var jsonData = await CrossFacebookClient.Current.RequestUserDataAsync ( new string[] { "id", "name", "email", "first_name", "last_name" }, new string[] { } ); var data = JObject.Parse(jsonData.Data); var Profile = new FacebookProfile() { Id = data["id"].ToString(), FullName = data["name"].ToString(), Email = data["email"].ToString(), LastName = data["last_name"].ToString(), FirstName = data["first_name"].ToString() }; var accesstoken = await _apiServices.LoginAsync(Profile.Email, Profile.Id); if (accesstoken != null) { int OS = 0; if (Device.RuntimePlatform.Equals("iOS")) { OS = 1; } Settings.AccessToken = accesstoken; var c = new Cliente { Correo = Profile.Email, DeviceID = Settings.DeviceID, SistemaOperativo = OS }; var response = await ApiServices.InsertarAsync <Cliente>(c, new System.Uri(Constants.BaseApiAddress), "/api/Clientes/GetClientData"); var cliente = JsonConvert.DeserializeObject <Cliente>(response.Result.ToString()); Settings.idCliente = cliente.IdCliente; Settings.Username = Profile.Email; Settings.Password = Profile.Id; IsBusy = false; Application.Current.MainPage = new NavigationPage(new MasterTabPage()); IsVisible = true; IsBusy = false; } else { await Application.Current.MainPage.Navigation.PushAsync(new AfterFBPage(Profile)); IsVisible = true; IsBusy = false; } } catch (Exception ex) { Debug.Write(ex.Message); } // Debug.WriteLine(data.Count); }
public Usuarios(FacebookProfile obj) { Name = obj.Name; Picture = obj.Picture.Data.Url; Id = obj.Id; Email = obj.email; }
public async Task <UserEntity> AddUserAsync(FacebookProfile model) { UserEntity userEntity = new UserEntity { Address = "...", Document = "...", Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, PicturePath = model.Picture?.Data?.Url, PhoneNumber = "...", Team = await _context.Teams.FirstOrDefaultAsync(t => t.Name == "Colombia"), UserName = model.Email, UserType = UserType.User, LoginType = LoginType.Facebook }; IdentityResult result = await _userManager.CreateAsync(userEntity, model.Id); if (result != IdentityResult.Success) { return(null); } UserEntity newUser = await GetUserAsync(model.Email); await AddUserToRoleAsync(newUser, userEntity.UserType.ToString()); return(newUser); }
public static async Task <FacebookProfile> GetFacebookAsync(string token) { //normally this is the somewhat basic form to do a get request; //Looking more into http client, you can do a lot more; using HttpClient client = new HttpClient(); //you can also add to the header by choosing the default headers available in a standard http request using //client.DefaultRequestHeaders.Authorization or whatever you want //or adding a custom //client.DefaultRequestHeaders.Add("name", "value"); string uri = $"https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email,picture,id,graphDomain&access_token={token}"; var response = await client.GetStringAsync(uri); FacebookProfile profile = null; if (!string.IsNullOrEmpty(response)) { try { profile = JsonSerializer.Deserialize <FacebookProfile>(response); } catch (Exception ex) { Debug.WriteLine($"Something bad happened: {ex.Message}"); } } return(profile); }
public LoginViewModel() { Profile = new FacebookProfile(); OnLoginCommand = new Command(async() => await LoginAsync()); OnShareDataCommand = new Command(async() => await ShareDataAsync()); OnLoadDataCommand = new Command(async() => await LoadData()); OnLogoutCommand = new Command(() => { if (CrossFacebookClient.Current.IsLoggedIn) { CrossFacebookClient.Current.Logout(); IsLoggedIn = false; } }); //OnFacebookLoginSuccessCmd = new Command<string>( // (authToken) => DisplayAlert("Success", $"Authentication succeed: {authToken}")); OnFacebookLoginSuccessCmd = new Command <string>( (authToken) => { //DisplayAlert("Success", $"Authentication succeed: {authToken}"); OnLoginSuccessful?.Invoke(this, new EventArgs()); }); OnFacebookLoginErrorCmd = new Command <string>( (err) => DisplayAlert("Error", $"Authentication failed: {err}")); OnFacebookLoginCancelCmd = new Command( () => DisplayAlert("Cancel", "Authentication cancelled by the user.")); //Posts = new ObservableCollection<FacebookPost>(); //LoadDataCommand.Execute(null); }
private void SetFacebookProfile(FacebookProfile profile) { Image profilePicture = new Image { Source = ImageSource.FromUri(new Uri( "https://graph.facebook.com/" + profile.Id + "/picture?width=450&height=450")) }; Label lblName = new Label { Text = profile.Name, FontSize = 24, FontAttributes = FontAttributes.Bold, TextColor = Color.Black }; StackLayout layout = new StackLayout { Padding = 10, Spacing = 10, HorizontalOptions = LayoutOptions.Center, Children = { profilePicture, lblName } }; Content = layout; }
public async Task <UserEntity> AddUserAsync(FacebookProfile model) { UserEntity userEntity = new UserEntity { Document = "...", Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, PicturePath = model.Picture?.Data?.Url, PhoneNumber = "...", UserName = model.Email, UserType = UserType.CallAdviser, LoginType = LoginType.Facebook, UserCode = GetUserCode(model.FirstName, model.LastName), Campaign = await _campaignHelper.GetCampaign(1) }; IdentityResult result = await _userManager.CreateAsync(userEntity, model.Id); if (result != IdentityResult.Success) { return(null); } UserEntity newUser = await GetUserAsync(model.Email); await AddUserToRoleAsync(newUser, userEntity.UserType.ToString()); return(newUser); }
public async Task <ApplicationUser> AddUserAsync(FacebookProfile model) { var userEntity = new ApplicationUser { Address = "...", Email = model.Email, Name = model.FirstName, // LastName = model.LastName, // ImageFacebook = model.Picture?.Data?.Url, PhoneNumber = "...", UserName = model.Email, // UserType = UserType.User, // LoginType = LoginType.Facebook, // ImageId = Guid.Empty }; IdentityResult result = await _userManager.CreateAsync(userEntity, model.Id); if (result != IdentityResult.Success) { return(null); } ApplicationUser newUser = await GetUserByEmailAsync(model.Email); await AddUserToRoleAsync(newUser, "Facebook");// userEntity.UserType.ToString()); return(newUser); }
public async Task <User> AuthorizeFacebookUser(string accessToken) { var fbConfig = _configuration.GetSection("Authentication:Facebook"); var request = _facebookApiService.PrepareProfileFetchRequest(HttpMethod.Get, fbConfig["GetUserPath"], accessToken); var response = await _facebookApiService.SendRequestAsync(request, fbConfig["GraphHostname"]); var user = new User(); if (response.Content != null) { Stream json = await response.Content.ReadAsStreamAsync(); FacebookProfile fbProfile = await JsonSerializer.DeserializeAsync <FacebookProfile>(json, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); user = await _userRepository.GetFirstByFilterAsync(u => u.Email == fbProfile.Email); if (fbProfile.Email != null && fbProfile.Name != null && fbProfile.Id != null && user == null) { user = new User { Email = fbProfile.Email, Name = fbProfile.Name, ProviderId = fbProfile.Id, ProviderName = "Facebook" }; await _userRepository.AddAsync(user); } } return(user); }
public NotificationsPage() { InitializeComponent(); var appData = Application.Current as App; _profile = appData.Profile; circleImage.Source = _profile.Picture.Data.Url; var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += (s, e) => { ActionSheetResult(s, e); }; btnMenu.GestureRecognizers.Add(tapGestureRecognizer); async void ActionSheetResult(object sender, EventArgs e) { var action = await DisplayActionSheet(null, null, null, "Notification Settings", "About Spokesman"); if (action == "About Spokesman") { await Navigation.PushAsync(new InfoPage()); } } }
public async Task <User> AddUserAsync(FacebookProfile model) { User userEntity = new User { Address = "...", Document = "...", Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, ImageFacebook = model.Picture?.Data?.Url, PhoneNumber = "...", City = await _context.Cities.FirstOrDefaultAsync(), UserName = model.Email, UserType = UserType.User, LoginType = LoginType.Facebook, ImageId = Guid.Empty }; IdentityResult result = await _userManager.CreateAsync(userEntity, model.Id); if (result != IdentityResult.Success) { return(null); } User newUser = await GetUserAsync(model.Email); await AddUserToRoleAsync(newUser, userEntity.UserType.ToString()); return(newUser); }
private void NotifyFacebookProfileRetreived(FacebookProfile fbProfile) { if (this.FacebookProfileRetreivedEvent != null) { this.FacebookProfileRetreivedEvent(this, new FacebookProfileEventArgs(fbProfile)); } }
public MyProfileViewModel() { Profile = new FacebookProfile(); Posts = new ObservableCollection <FacebookPost>(); 
 LoadDataCommand = new Command(async() => await LoadData()); PostMessageCommand = new Command <string>(async(msg) => await PostAsync(msg)); LoadDataCommand.Execute(null); }
private FacebookProfile DeserializeProfile(string response) { Dictionary <string, object> responseObject = Json.Deserialize(response) as Dictionary <string, object>; FacebookProfile profile = new FacebookProfile(); if (responseObject != null) { object val; if (responseObject.TryGetValue("id", out val)) { profile.Id = (string)val; } if (responseObject.TryGetValue("first_name", out val)) { profile.FirstName = (string)val; } if (responseObject.TryGetValue("last_name", out val)) { profile.LastName = (string)val; } } return(profile); }
public RegisterPageViewModel() { _apiService = new ApiService(); criptografia = new Criptografia(); Os_Folder = App.Os_Folder; Profile = new FacebookProfile(); OnLoginCommand = new Command(async() => await LoginAsync()); OnShareDataCommand = new Command(async() => await ShareDataAsync()); OnLoadDataCommand = new Command(async() => await LoadData()); OnLogoutCommand = new Command(() => { if (CrossFacebookClient.Current.IsLoggedIn) { CrossFacebookClient.Current.Logout(); IsLoggedIn = false; } }); OnSomeCommand(); selectedState = "MX"; SubmitCommand = new Command(OnSubmit); }
public async Task SetFacebookUserProfileAsync(string accessToken) { // var facebookServices = new FacebookServices(); var requestUrl2 = "https://graph.facebook.com/v2.7/me?fields=name,picture.type(large),age_range&access_token=" + accessToken; //"https://graph.facebook.com/v2.7/me?fields=name,picture,work,website,religion,location,locale,link,cover,age_range,birthday,devices,email,first_name,last_name,gender,hometown,is_verified,languages&access_token=" //"https://graph.facebook.com/v2.7/me?fields=name,picture&access_token=EAASsWWQcRbcBAFZAhPz61EHMJaL04R7cOA2vU5H6hnLu34b83heQYFYKoAcufBZAly5XUD3muv3nlNDLvnlMvt9VpVA1ZCit20vQE7HgBBRH2ZBoQvUzofXS4EZAGfoauZAuyUkCCKmYQZBaypPFUKKnwHRv1E09h1zySXSSr0IY6PLYRtHEZCHX" var httpClient = new HttpClient(); System.Diagnostics.Debug.WriteLine(requestUrl2); var userJson = await httpClient.GetStringAsync(requestUrl2); var facebookProfile = JsonConvert.DeserializeObject <FacebookProfile>(userJson); FacebookProfile = facebookProfile; //Database.AddAthlete(facebookProfile.Id, facebookProfile.Name,0,0,false); // FacebookProfile = await facebookServices.GetFacebookProfileAsync(accessToken); }
protected override async void OnAppearing() { base.OnAppearing(); //using System.Net.Http; //using System.Net.Http.Headers; //using Newtonsoft.Json; var httpClient = new HttpClient(); try { var request = new HttpRequestMessage(); request.RequestUri = new Uri("https://graph.facebook.com/v3.1/me?fields=id,name,picture,email,birthday"); request.Method = HttpMethod.Post; //request.Content = new StringContent("sdasdasdasd"); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", FbToken); var response = await httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { var body = await response.Content.ReadAsStringAsync(); FacebookProfile profile = JsonConvert.DeserializeObject <FacebookProfile>(body); BindingContext = profile; } } catch (Exception) { // throw; } }
public void LoginViewModelInit() { //Facebook Login Profile = new FacebookProfile(); _realm.Write(() => { // Remove the instance from the realm. _realm.RemoveAll(); // Discard the reference. }); OnLoginCommand = new Command(async() => await FacebookLoginAsync()); OnLoadDataCommand = new Command(async() => await FacebookLoadData()); OnLogoutCommand = new Command(() => { // Add logout method }); //GOOGLE LoginCommand = new Command(LoginAsync); //Custom Login LoginOnClick = new Command(LocalAuth); //RestThePassword = new Command(RestPassword); RegisterOnClick = new Command(RegisterUser); IsLoggedIn = false; }
private void SetPageContent(FacebookProfile facebookProfile) { Content = new StackLayout { Orientation = StackOrientation.Vertical, Padding = new Thickness(8, 30), Children = { new Label { Text = facebookProfile.Name, TextColor = Color.Black, FontSize = 22, }, new Label { Text = facebookProfile.Id, TextColor = Color.Black, FontSize = 22, }, new Label { Text = facebookProfile.IsVerified.ToString(), TextColor = Color.Black, FontSize = 22, }, new Label { Text = facebookProfile.Devices.FirstOrDefault().Os, TextColor = Color.Black, FontSize = 22, }, new Label { Text = facebookProfile.Gender, TextColor = Color.Black, FontSize = 22, }, new Label { Text = facebookProfile.AgeRange.Min.ToString(), TextColor = Color.Black, FontSize = 22, }, new Label { Text = facebookProfile.Picture.Data.Url, TextColor = Color.Black, FontSize = 22, }, new Label { Text = facebookProfile.Cover.Source, TextColor = Color.Black, FontSize = 22, }, } }; }
public AfterFBPage(FacebookProfile facebookProfile) { InitializeComponent(); //Message.Text = string.Format("Bienvenido {0}, ayudanos con estos datos para poder brindarte el mejor servicio.",facebookProfile.FullName); BindingContext = new AfterFBViewModel(facebookProfile); }
public async Task GetFacebookProfileAsync(string accessToken) { var service = new FacebookService(); FacebookProfile = await service.GetFacebookProfileAsync(accessToken); Helpers.Settings.FacebookID = FacebookProfile.Id; }
public async Task <FacebookProfile> GetProfile(string code) { AccessTokenResponse token = await Get <AccessTokenResponse>($"https://graph.facebook.com/v7.0/oauth/access_token?client_id={_clientId}&redirect_uri={_config["url:ui"]}/accounts/facebook-auth&client_secret={_clientSecret}&code={code}"); FacebookProfile profile = await Get <FacebookProfile>($"https://graph.facebook.com/me?fields=email,name,picture&access_token={token.Access_Token}"); return(profile); }
public OwnerProfile() { userProfile = new UserProfile(); facebookProfile = new FacebookProfile(); lives = new Lives(); level_data = new LevelData(); inbox = new Inbox(); }
async void Login() { var appData = Application.Current as App; _fbProfile = appData.Profile; await Navigation.PushModalAsync(new MainPage()); }
async void Handle_Clicked(object sender, System.EventArgs e) { var appData = Application.Current as App; _fbProfile = appData.Profile; await Navigation.PushModalAsync(new MainPage()); }
private void OnFacebookProfileRetreived(object sender, FacebookProfileEventArgs e) { this.profile = e.Profile; if (this.ProfileName != null) { this.ProfileName.text = string.Format("Hello {0} ", this.profile.FirstName, this.profile.LastName); } }
public object Deserialize(JsonValue json, JsonMapper mapper) { FacebookProfile profile = null; if (json != null && !json.IsNull) { profile = new FacebookProfile(); // 04/14/2012 Paul. Should not have both id and uid. profile.ID = json.ContainsName("id") ? json.GetValue <string>("id") : String.Empty; profile.ID = json.ContainsName("uid") ? json.GetValue <string>("uid") : profile.ID; profile.Username = json.ContainsName("username") ? json.GetValue <string>("username") : String.Empty; profile.Name = json.ContainsName("name") ? json.GetValue <string>("name") : String.Empty; profile.FirstName = json.ContainsName("first_name") ? json.GetValue <string>("first_name") : String.Empty; profile.LastName = json.ContainsName("last_name") ? json.GetValue <string>("last_name") : String.Empty; profile.Gender = json.ContainsName("gender") ? json.GetValue <string>("gender") : String.Empty; profile.Locale = json.ContainsName("locate") ? json.GetValue <string>("locate") : String.Empty; profile.MiddleName = json.ContainsName("middle_name") ? json.GetValue <string>("middle_name") : String.Empty; // 04/14/2012 Paul. Should not have both email and contact_email. profile.Email = json.ContainsName("email") ? json.GetValue <string>("email") : String.Empty; profile.Email = json.ContainsName("contact_email") ? json.GetValue <string>("contact_email") : profile.Email; profile.Link = json.ContainsName("link") ? json.GetValue <string>("link") : String.Empty; profile.ThirdPartyId = json.ContainsName("third_party_id") ? json.GetValue <string>("third_party_id") : String.Empty; profile.Timezone = json.ContainsName("timezone") ? json.GetValue <int>("timezone") : 0; profile.Verified = json.ContainsName("verified") ? json.GetValue <bool>("verified") : false; profile.About = json.ContainsName("about") ? json.GetValue <string>("about") : String.Empty; profile.About = json.ContainsName("about_me") ? json.GetValue <string>("about_me") : profile.About; profile.Bio = json.ContainsName("bio") ? json.GetValue <string>("bio") : String.Empty; profile.Religion = json.ContainsName("religion") ? json.GetValue <string>("religion") : String.Empty; profile.Political = json.ContainsName("political") ? json.GetValue <string>("political") : String.Empty; profile.Quotes = json.ContainsName("quotes") ? json.GetValue <string>("quotes") : String.Empty; profile.RelationshipStatus = json.ContainsName("relationship_status") ? json.GetValue <string>("relationship_status") : String.Empty; profile.Website = json.ContainsName("website") ? json.GetValue <string>("website") : String.Empty; // http://developers.facebook.com/docs/reference/fql/user/ // The birthday of the user being queried. The format of this date varies based on the user's locale. profile.Birthday = json.ContainsName("birthday") ? JsonUtils.ToDateTime(json.GetValue <string>("birthday"), "MM/dd/yyyy") : DateTime.MinValue; // The birthday of the user being queried in MM/DD/YYYY format. profile.Birthday = json.ContainsName("birthday_date") ? JsonUtils.ToDateTime(json.GetValue <string>("birthday_date"), "MM/dd/yyyy") : profile.Birthday; profile.UpdatedTime = json.ContainsName("updated_time") ? JsonUtils.ToDateTime(json.GetValue <string>("updated_time"), "yyyy-MM-ddTHH:mm:ss") : DateTime.MinValue; profile.Location = mapper.Deserialize <Reference>(json.GetValue("location")); profile.Hometown = mapper.Deserialize <Reference>(json.GetValue("hometown")); if (json.ContainsName("hometown_location")) { profile.Hometown = mapper.Deserialize <Reference>(json.GetValue("hometown_location")); } profile.SignificantOther = mapper.Deserialize <Reference>(json.GetValue("significant_other")); profile.Work = mapper.Deserialize <List <WorkEntry> >(json.GetValue("work")); profile.Education = mapper.Deserialize <List <EducationEntry> >(json.GetValue("education")); profile.InterestedIn = mapper.Deserialize <List <String> >(json.GetValue("interested_in")); profile.InspirationalPeople = mapper.Deserialize <List <Reference> >(json.GetValue("inspirational_people")); profile.Languages = mapper.Deserialize <List <Reference> >(json.GetValue("languages")); profile.Sports = mapper.Deserialize <List <Reference> >(json.GetValue("sports")); profile.FavoriteTeams = mapper.Deserialize <List <Reference> >(json.GetValue("favorite_teams")); profile.FavoriteAtheletes = mapper.Deserialize <List <Reference> >(json.GetValue("favorite_athletes")); } return(profile); }
public async Task SetFacebookUserProfileAsync(string accessToken) { var facebookServices = new FacebookServices(); var face = FacebookProfile = await facebookServices.GetFacebookProfileAsync(accessToken); Settings.IsEmailIn = face.email; Settings.IsUserdIn = face.FirstName + " " + face.LastName; }
// Create facebook profile card. private Attachment GetProfileCard(FacebookProfile profile, string userName) { var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0)); card.Body.Add(new AdaptiveTextBlock() { Text = $"User Information", Size = AdaptiveTextSize.Default }); card.Body.Add(new AdaptiveColumnSet() { Columns = new List <AdaptiveColumn>() { new AdaptiveColumn() { Items = new List <AdaptiveElement>() { new AdaptiveImage() { Url = new Uri(profile.ProfilePicture.data.url), Size = AdaptiveImageSize.Medium, Style = AdaptiveImageStyle.Person } }, Width = "auto" }, new AdaptiveColumn() { Items = new List <AdaptiveElement>() { new AdaptiveTextBlock() { Text = $"Hello! {profile.Name}", Weight = AdaptiveTextWeight.Bolder, IsSubtle = true }, new AdaptiveTextBlock() { Text = $"User name : {userName}", Weight = AdaptiveTextWeight.Bolder, IsSubtle = true } }, Width = "stretch" } } }); return(new Attachment() { ContentType = AdaptiveCard.ContentType, Content = card, }); }
public object Deserialize(JsonValue json, JsonMapper mapper) { FacebookProfile profile = null; if ( json != null && !json.IsNull ) { profile = new FacebookProfile(); // 04/14/2012 Paul. Should not have both id and uid. profile.ID = json.ContainsName("id" ) ? json.GetValue<string>("id" ) : String.Empty; profile.ID = json.ContainsName("uid" ) ? json.GetValue<string>("uid" ) : profile.ID; profile.Username = json.ContainsName("username" ) ? json.GetValue<string>("username" ) : String.Empty; profile.Name = json.ContainsName("name" ) ? json.GetValue<string>("name" ) : String.Empty; profile.FirstName = json.ContainsName("first_name" ) ? json.GetValue<string>("first_name" ) : String.Empty; profile.LastName = json.ContainsName("last_name" ) ? json.GetValue<string>("last_name" ) : String.Empty; profile.Gender = json.ContainsName("gender" ) ? json.GetValue<string>("gender" ) : String.Empty; profile.Locale = json.ContainsName("locate" ) ? json.GetValue<string>("locate" ) : String.Empty; profile.MiddleName = json.ContainsName("middle_name" ) ? json.GetValue<string>("middle_name" ) : String.Empty; // 04/14/2012 Paul. Should not have both email and contact_email. profile.Email = json.ContainsName("email" ) ? json.GetValue<string>("email" ) : String.Empty; profile.Email = json.ContainsName("contact_email" ) ? json.GetValue<string>("contact_email" ) : profile.Email; profile.Link = json.ContainsName("link" ) ? json.GetValue<string>("link" ) : String.Empty; profile.ThirdPartyId = json.ContainsName("third_party_id" ) ? json.GetValue<string>("third_party_id" ) : String.Empty; profile.Timezone = json.ContainsName("timezone" ) ? json.GetValue<int >("timezone" ) : 0; profile.Verified = json.ContainsName("verified" ) ? json.GetValue<bool >("verified" ) : false; profile.About = json.ContainsName("about" ) ? json.GetValue<string>("about" ) : String.Empty; profile.About = json.ContainsName("about_me" ) ? json.GetValue<string>("about_me" ) : profile.About; profile.Bio = json.ContainsName("bio" ) ? json.GetValue<string>("bio" ) : String.Empty; profile.Religion = json.ContainsName("religion" ) ? json.GetValue<string>("religion" ) : String.Empty; profile.Political = json.ContainsName("political" ) ? json.GetValue<string>("political" ) : String.Empty; profile.Quotes = json.ContainsName("quotes" ) ? json.GetValue<string>("quotes" ) : String.Empty; profile.RelationshipStatus = json.ContainsName("relationship_status") ? json.GetValue<string>("relationship_status") : String.Empty; profile.Website = json.ContainsName("website" ) ? json.GetValue<string>("website" ) : String.Empty; // http://developers.facebook.com/docs/reference/fql/user/ // The birthday of the user being queried. The format of this date varies based on the user's locale. profile.Birthday = json.ContainsName("birthday" ) ? JsonUtils.ToDateTime(json.GetValue<string>("birthday" ), "MM/dd/yyyy" ) : DateTime.MinValue; // The birthday of the user being queried in MM/DD/YYYY format. profile.Birthday = json.ContainsName("birthday_date" ) ? JsonUtils.ToDateTime(json.GetValue<string>("birthday_date"), "MM/dd/yyyy" ) : profile.Birthday; profile.UpdatedTime = json.ContainsName("updated_time" ) ? JsonUtils.ToDateTime(json.GetValue<string>("updated_time" ), "yyyy-MM-ddTHH:mm:ss") : DateTime.MinValue; profile.Location = mapper.Deserialize<Reference >(json.GetValue("location" )); profile.Hometown = mapper.Deserialize<Reference >(json.GetValue("hometown" )); if ( json.ContainsName("hometown_location") ) profile.Hometown = mapper.Deserialize<Reference>(json.GetValue("hometown_location")); profile.SignificantOther = mapper.Deserialize<Reference >(json.GetValue("significant_other" )); profile.Work = mapper.Deserialize<List<WorkEntry >>(json.GetValue("work" )); profile.Education = mapper.Deserialize<List<EducationEntry>>(json.GetValue("education" )); profile.InterestedIn = mapper.Deserialize<List<String >>(json.GetValue("interested_in" )); profile.InspirationalPeople = mapper.Deserialize<List<Reference >>(json.GetValue("inspirational_people")); profile.Languages = mapper.Deserialize<List<Reference >>(json.GetValue("languages" )); profile.Sports = mapper.Deserialize<List<Reference >>(json.GetValue("sports" )); profile.FavoriteTeams = mapper.Deserialize<List<Reference >>(json.GetValue("favorite_teams" )); profile.FavoriteAtheletes = mapper.Deserialize<List<Reference >>(json.GetValue("favorite_athletes" )); } return profile; }
public async Task SetFacebookUserProfileAsync(string accessToken) { if (UserServices.currentUser.FromFacebook) { var facebookServices = new FacebookServices(); FacebookProfile = await facebookServices.GetFacebookProfileAsync(accessToken); UserServices.currentUser.SetUser(FacebookProfile); } }
public override void ViewWillAppear(bool animated) { this.Email.Background = UIImage.FromFile ("./Assets/input.png"); this.Password.Background = UIImage.FromFile ("./Assets/input.png"); this.Login.SetBackgroundImage (UIImage.FromFile ("./Assets/buttonlong.png"), UIControlState.Normal); this.Email.LeftView = new UIView (new RectangleF (0, 0, 5, 30)); this.Email.LeftViewMode = UITextFieldViewMode.Always; this.Password.LeftView = new UIView (new RectangleF (0, 0, 5, 30)); this.Password.LeftViewMode = UITextFieldViewMode.Always; var button = new UIBarButtonItem ("Back", UIBarButtonItemStyle.Plain, null); var custom = new UIButton (new RectangleF (0, 0, 26, 15)); custom.SetBackgroundImage(UIImage.FromFile("./Assets/back.png"), UIControlState.Normal); custom.TouchUpInside += (sender, e) => NavigationController.PopViewControllerAnimated (true); button.CustomView = custom; this.NavigationItem.LeftBarButtonItem = button; this.NavigationController.SetNavigationBarHidden (false, false); // FACEBOOK LOGIN fbLogin = new FBLoginView (AppDelegate.Permissions); FacebookView.AddSubview (fbLogin); fbLogin.SizeToFit (); fbLogin.FetchedUserInfo += (object sender, FBLoginViewUserInfoEventArgs e) => { if (FBSession.ActiveSession.IsOpen) { var model = new FacebookProfile { Id = long.Parse (e.User.Id), Name = e.User.Name, first_name = e.User.FirstName, last_name = e.User.LastName, Birthday = e.User.Birthday, Email = e.User.ObjectForKey ("email").ToString (), UserName = e.User.Username }; var request = new RestRequest (); request.RequestFinished += (object sendr, RequestEndedArgs ev) => { var jsonId = (int)JsonConvert.DeserializeObject (ev.Result, typeof(int)); InvokeOnMainThread (delegate { AppDelegate.SaveProfileId(jsonId); var tabbar = new MainTabController(); UIApplication.SharedApplication.Delegate.Window.RootViewController = tabbar; }); }; request.Send (RequestConfig.Facebook, "POST", model); } }; fbLogin.ShowingLoggedOutUser += (object sender, EventArgs e) => { Console.WriteLine(e.ToString()); }; fbLogin.ShowingLoggedInUser += (object sender, EventArgs e) => { Console.WriteLine("Logged in."); }; // GOOGLE LOGIN var signIn = SignIn.SharedInstance; signIn.ClientId = AppDelegate.GoogleClientId; signIn.Scopes = new [] { PlusConstants.AuthScopePlusLogin, PlusConstants.AuthScopePlusMe, "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email" }; signIn.ShouldFetchGoogleUserEmail = true; signIn.ShouldFetchGoogleUserId = true; signIn.Finished += (object sender, SignInDelegateFinishedEventArgs e) => { if(e.Error != null) { InvokeOnMainThread(delegate { new UIAlertView("Error.", "Could not sign in.", null, "Ok", null).Show(); }); } else { var request = new RestRequest(); request.RequestFinished += (object sendr, RequestEndedArgs ev) => { var data = (GoogleClient)JsonConvert.DeserializeObject(ev.Result, typeof(GoogleClient)); var request2 = new RestRequest(); request2.RequestFinished += (object sndr, RequestEndedArgs evnt) => { var jsonId = (int)JsonConvert.DeserializeObject (evnt.Result, typeof(int)); InvokeOnMainThread (delegate { AppDelegate.SaveProfileId(jsonId); var tabbar = new MainTabController(); UIApplication.SharedApplication.Delegate.Window.RootViewController = tabbar; }); }; request2.Send(RequestConfig.Google, "POST", data); }; request.Send(String.Format(RequestConfig.GoogleFetch, Uri.EscapeDataString(signIn.Authentication.AccessToken)), "GET"); } }; var signInButton = new SignInButton (); GoogleView.AddSubview (signInButton); signInButton.Frame = new RectangleF (0, 0, GoogleView.Frame.Size.Width - 8, GoogleView.Frame.Size.Height); signInButton.SizeToFit (); }
public void AddProfile(FacebookProfile profile) { _profileCache.SetValue(profile.UserId, profile); }