示例#1
0
        private async void btnFace_Clicked(object sender, EventArgs e)
        {
            var accounts = _services.Accounts;

            if (accounts.Contains(LoginServices.Facebook))
            {
                var access_token = _services.GetPropertyFromAccount(LoginServices.Facebook, "access_token");
                var fbUri        = new Uri("https://graph.facebook.com/me?fields=first_name,last_name,picture,age_range,email,gender,is_verified&access_token=" + access_token);
                var httpClient   = new HttpClient(new LoggingHandler(new HttpClientHandler()));
                httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("token", access_token);
                var response = await httpClient.GetAsync(fbUri);

                if (response.IsSuccessStatusCode)
                {
                    var content = await response.Content.ReadAsStringAsync();

                    var a = (JObject)JsonConvert.DeserializeObject(content);
                    usuariosService = new UsuariosService();
                    var resultado = await usuariosService.PostUsuarioFaceAsync(content);

                    if (resultado == "added" || resultado == "logged")
                    {
                        UsuariosEventosService usuariosEventosService = new UsuariosEventosService();
                        UsuariosEventos        usuariosEventos        = new UsuariosEventos();
                        SesionService          sesionService          = new SesionService();
                        var idUsuarios = await sesionService.GetSesionIdUserDbAsync();

                        usuariosEventos.idEvento  = evento.idEventos;
                        usuariosEventos.idUsuario = idUsuarios;
                        var resultadoUE = await usuariosEventosService.setUsuarioEvento(usuariosEventos);

                        Navigation.InsertPageBefore(new DetalleEventoPage(evento), this);
                        await Navigation.PopAsync();
                    }
                    var login = a["fisrt_name"];
                    var image = "https://graph.facebook.com/me/picture?access_token=" + access_token;
                }
            }
            else
            {
                AuthorizePage authorizePage = new AuthorizePage(LoginServices.Facebook, this);
                var           waitHandle    = new EventWaitHandle(false, EventResetMode.AutoReset);
                authorizePage.Disappearing += (sender2, e2) =>
                {
                    ExtraerInfoFacebook();
                };
                await Navigation.PushAsync(authorizePage);
            }
        }
示例#2
0
        private async Task ExtraerInfoFacebook()
        {
            var accounts = _services.Accounts;

            if (accounts.Contains(LoginServices.Facebook))
            {
                var access_token = _services.GetPropertyFromAccount(LoginServices.Facebook, "access_token");
                var fbUri        = new Uri("https://graph.facebook.com/me?fields=first_name,last_name,picture.width(300).height(300),age_range,email,gender,is_verified&access_token=" + access_token);
                var httpClient   = new HttpClient(new LoggingHandler(new HttpClientHandler()));
                httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("token", access_token);
                var response = await httpClient.GetAsync(fbUri);

                if (response.IsSuccessStatusCode)
                {
                    var content = await response.Content.ReadAsStringAsync();

                    var a = (JObject)JsonConvert.DeserializeObject(content);
                    usuariosService = new UsuariosService();
                    var resultado = await usuariosService.PostUsuarioFaceAsync(content);

                    if (resultado == "added")
                    {
                        UsuariosEventosService usuariosEventosService = new UsuariosEventosService();
                        UsuariosEventos        usuariosEventos        = new UsuariosEventos();
                        SesionService          sesionService          = new SesionService();
                        var idUsuarios = await sesionService.GetSesionIdUserDbAsync();

                        usuariosEventos.idEvento  = evento.idEventos;
                        usuariosEventos.idUsuario = idUsuarios;
                        var resultadoUE = await usuariosEventosService.setUsuarioEvento(usuariosEventos);

                        Navigation.InsertPageBefore(new DetalleEventoPage(evento), this);
                        await Navigation.PopAsync();
                    }
                    if (resultado == "logged")
                    {
                        Navigation.InsertPageBefore(new DetalleEventoPage(evento), this);
                        await Navigation.PopAsync();
                    }
                }
            }
        }