public LoginPageRenderer() { var activity = Context as Activity; var auth = new OAuth2Authenticator( clientId: "168703917051703", //clientId: "525812214440244", scope: "", authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"), redirectUrl: new Uri("http://www.facebook.com/connect/login_success.html")); auth.Completed += async(sender, eventArgs) => { if (eventArgs.IsAuthenticated) { var accessToken = eventArgs.Account.Properties["access_token"].ToString(); var expiresIn = Convert.ToDouble(eventArgs.Account.Properties["expires_in"]); var expiryDate = DateTime.Now + TimeSpan.FromSeconds(expiresIn); var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me?fields=id,name,email,picture"), null, eventArgs.Account); var response = await request.GetResponseAsync(); var obj = JObject.Parse(response.GetResponseText()); var objs = JsonConvert.DeserializeObject <FacebookProfile>(response.GetResponseText()); Usuarios usuario = new Usuarios(objs); Usuario usuariobd = new Usuario(objs); var token = FirebaseInstanceId.Instance.Token; ObtenerResul obtenerResul = new ObtenerResul(); string nombreuser = usuario.Name; var contador = await obtenerResul.GetList <ClasesBd>("http://tools.agorafranquicias.com/APP/Consultas/getUsuarios.php?Name='" + nombreuser + "'"); int total = 0; foreach (Total t in contador.Total) { total = t.Contador; } if (total == 0) { obtenerResul.SaveUser(usuariobd, token); } else { obtenerResul.UpdateUser(usuariobd, token); } using (var datos = new DataAccess()) { datos.InserUsuario(usuario); } await App.NavigateToProfile(objs); } else { await App.VueltaAtras(); } }; activity.StartActivity(auth.GetUI(activity)); }
//Método que muestra toda la carta que hay para domicilio private void domicilio() { var template = new DataTemplate(typeof(DefaultTemplate)); var view = new AccordionView(template); List <Section> ListaCategoria = new List <Section>(); List <ShoppingCart> ListaProductos = null; view.SetBinding(AccordionView.ItemsSourceProperty, "List"); view.Template.SetBinding(AccordionSectionView.TitleProperty, "Title"); view.Template.SetBinding(AccordionSectionView.ItemsSourceProperty, "List"); Xamarin.Forms.Device.BeginInvokeOnMainThread(async() => { ObtenerResul obtenerResul = new ObtenerResul(); var img = await obtenerResul.GetList <ClasesBd>("http://tools.agorafranquicias.com/APP/Consultas/nombreImagenCategoriaDomicilio.php"); var prod = await obtenerResul.GetList <ClasesBd>("http://tools.agorafranquicias.com/APP/Consultas/ShoppingCart.php"); if (img != null) { foreach (BD.NombreImagenCategoria Cat in img.Nombreimagencategoria) { ListaProductos = new List <ShoppingCart>(); foreach (ShoppingCart productos in prod.ShoppingCart) { if (Cat.Id == productos.Id_Categoria) { ListaProductos.Add(productos); } } ListaCategoria.Add(new Section { Title = Cat.URL, List = ListaProductos }); } view.BindingContext = new ViewModel { List = ListaCategoria }; this.Content = view; } else { await Navigation.PushPopupAsync(new DialogoError()); } Image Llamar = new Image() { Source = "http://tools.agorafranquicias.com/APP/Images/Otros/Llamar.jpg", WidthRequest = 500, }; var TapedLlamar = new TapGestureRecognizer(); TapedLlamar.Tapped += TapImgLlamar; Llamar.GestureRecognizers.Add(TapedLlamar); AbsoluteLayout AbsoluteLayout = new AbsoluteLayout(); AbsoluteLayout.SetLayoutBounds(Llamar, new Rectangle(55, 330, 250, 300)); AbsoluteLayout.SetLayoutBounds(view, new Rectangle(0, 0, 380, 430)); AbsoluteLayout.Children.Add(view); AbsoluteLayout.Children.Add(Llamar); this.Content = AbsoluteLayout; }); }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); if (done) { return; } var auth = new OAuth2Authenticator( clientId: "168703917051703", scope: "", authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"), redirectUrl: new Uri("http://www.facebook.com/connect/login_success.html")); auth.Completed += async(sender, eventArgs) => { if (eventArgs.IsAuthenticated) { var accessToken = eventArgs.Account.Properties["access_token"].ToString(); var expiresIn = Convert.ToDouble(eventArgs.Account.Properties["expires_in"]); var expiryDate = DateTime.Now + TimeSpan.FromSeconds(expiresIn); var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me?fields=id,name,cover,age_range,picture"), null, eventArgs.Account); var response = await request.GetResponseAsync(); var obj = JObject.Parse(response.GetResponseText()); var objs = JsonConvert.DeserializeObject <FacebookProfile>(response.GetResponseText()); Usuarios usuario = new Usuarios(objs); Usuario usuariobd = new Usuario(objs); ObtenerResul obtenerResul = new ObtenerResul(); string nombreuser = usuario.Name; var contador = await obtenerResul.GetList <ClasesBd>("http://tools.agorafranquicias.com/APP/Consultas/getUsuarios.php?Name='" + nombreuser + "'"); int total; foreach (Total t in contador.Total) { total = t.Contador; } /* if (total == 0) * { * obtenerResul.SaveUser(usuariobd, token); * } * else * { * obtenerResul.UpdateUser(usuariobd, token); * }*/ obtenerResul.SaveUser(usuariobd, null); using (var datos = new DataAccess()) { datos.InserUsuario(usuario); } await App.NavigateToPromos(); } else { await App.VolverPromociones(); } }; done = true; PresentViewController(auth.GetUI(), true, null); }