private async void Auth_Clicked(object sender, EventArgs e) { // Пример авторизации в vk.com через GET запрос try { string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "User.json"); await VKSession.Auth(login.Text, password.Text); File.WriteAllText(fileName, VKSession.user.Serialize()); // Скрываем наш модный попап popupLoginView.IsVisible = false; OpenNews(); } catch (HttpRequestException ex) { await DisplayAlert("Ошибка авторизации!", "Неверный логин или пароль!\n" + ex.Message, "OK"); } catch (Exception ex) { // Ошиба на случай, если упадет преобразование из JSON в VKJson await DisplayAlert("Иная ошибка!", ex.Message, "OK"); } }
public frmMain() { InitializeComponent(); // Initialize VKSession instance with TEST-ONLY VK application ID MyVK = new VKSession(appID: 4368411); }
public MainPage() { InitializeComponent(); string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "User.json"); if (File.Exists(fileName)) { try { string responseBody = File.ReadAllText(fileName); VKSession.Auth(responseBody); OpenNews(); } catch (HttpRequestException ex) { DisplayAlert("Ошибка авторизации!", "Неверный логин или пароль!\n" + ex.Message, "OK"); File.Delete(fileName); } catch (Exception ex) { // Ошиба на случай, если упадет преобразование из JSON в VKJson DisplayAlert("Иная ошибка!", ex.Message, "OK"); } } }
/// <summary> /// Initializes new OAuthLogin instance. /// </summary> /// <param name="authSession">VKSession instance to authorize</param> /// <param name="securityScope">Security options to request for session</param> public OAuthLoginAssistant(VKSession authSession, VK.SecurityFlag securityScope) { if (authSession == null) throw new ArgumentNullException("authSession"); else if (securityScope == VK.SecurityFlag.None) throw new ArgumentException("Invalid security flags. Specify at least one."); this.AuthSession = authSession; this.SecurityScope = securityScope; OK_REDIRECT_URL = ((securityScope & VK.SecurityFlag.NoHTTPS) != 0 ? "http" : "https") + OK_REDIRECT_URL; }
private async Task UpdateWall() { await VKSession.LoadNews(); var content = new ObservableCollection <FrameKostyl>(); StackLayout layout = new StackLayout(); foreach (var item in VKSession.news.Get().response.items) { /*public string type { get; set; } * public int source_id { get; set; } * public int date { get; set; } * public int post_id { get; set; } * public string post_type { get; set; } * public string text { get; set; } * public int marked_as_ads { get; set; } * public List<Attachment> attachments { get; set; } * public PostSource post_source { get; set; } * public Comments comments { get; set; } * public Likes likes { get; set; } * public Reposts reposts { get; set; } * public Views views { get; set; } * public bool is_favorite { get; set; } */ if (item.type == "post") { Frame frame = new Frame(); frame.CornerRadius = 10; frame.BackgroundColor = Color.FromHex("#31343a"); StackLayout stackLayout = new StackLayout(); Label label = new Label(); label.TextColor = Color.White; label.Text = item.text; stackLayout.Children.Add(label); if (item.attachments != null) { foreach (var attachment in item.attachments) { if (attachment.type == "photo") { /* * public int id { get; set; } * public int album_id { get; set; } * public int owner_id { get; set; } * public int user_id { get; set; } * public List<Size> sizes { get; set; } * public string text { get; set; } * public int date { get; set; } * public int post_id { get; set; } * public string access_key { get; set; } */ var tap = new TapGestureRecognizer(); tap.Tapped += TapGestureRecognizer_Tapped; Image image = new Image(); image.GestureRecognizers.Add(tap); if (attachment.photo.sizes != null) { image.Source = attachment.photo.sizes[attachment.photo.sizes.Count - 1].url; } stackLayout.Children.Add(image); } } } frame.Content = stackLayout; layout.Children.Add(frame); } } WallLayout.Children.Clear(); WallLayout.Children.Add(layout); loading.IsRunning = false; }