S
S
Sasha Pleshakov2016-05-18 16:39:02
In contact with
Sasha Pleshakov, 2016-05-18 16:39:02

How can I log in to Vknotakte from two accounts in one application?

I use the VK.NET library .
I log in using the LoginIn function.

private void LoginIn(VkApi vk, string login, string password)
        {
            vk.Authorize(new ApiAuthParams
            {
                ApplicationId = AppID,
                Login = login,
                Password = password,
                Settings = Settings.All
            });
        }

The problem is that after authorization of the second account, a VkApiAuthorizationException (wrong login or password) appears. In fact, a couple of login passwords are correct. An exception occurs only when the second account is authorized, regardless of the login and password.
Whole code:
public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private VkApi vk1 = new VkApi(), vk2 = new VkApi();

        #region logins
        private void LoginIn(VkApi vk, string login, string password)
        {
            vk.Authorize(new ApiAuthParams
            {
                ApplicationId = 5427437,
                Login = login,
                Password = password,
                Settings = Settings.All
            });
        }

        private void CheckBox1_Checked(object sender, RoutedEventArgs e)
        {
            LoginIn(vk1, Login1.Text, Password1.Text);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            vk1.Status.Set("1");
            vk2.Status.Set("2");
        }

        private void CheckBox2_Checked(object sender, RoutedEventArgs e)
        {
            LoginIn(vk2, Login2.Text, Password2.Text);
        }
        #endregion
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fat Lorrie, 2016-05-18
@mnepoh

The library sources are on github, why not look at the implementation and get information about the native (REST) ​​VK API?

if (!authorization.IsAuthorized)
{
    throw new VkApiAuthorizationException("Invalid authorization with {0} - {1}", emailOrPhone, password);
}
...
public bool IsAuthorized => !string.IsNullOrWhiteSpace(AccessToken);
....
private string AccessToken
{ get; set; }

Are you using different VkApi instances?

A
Archakov Dennis, 2016-05-18
@archakov06

Create an array of objects that will store the object of each element of this VK.NET library (authorized)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question