K
K
Konstantin Teploukhov2019-01-11 05:36:34
API
Konstantin Teploukhov, 2019-01-11 05:36:34

VK API - How to make it work, docs don't save (sig generation)?

Here is what I found from docks
1 and 2
Code that I have now

Cry
string login = ""; // Login
                string pass = ""; // Pass
                using (var request = new xNet.HttpRequest())
                {
                    request.Cookies = new CookieDictionary();
                    request.AllowAutoRedirect = false;
                    request.UserAgent = "VKAndroidApp/4.10.0-1151 (Android 4.4.2; SDK 19; armeabi-v7a; LGE LGM-V300K; ru)";
                    request.AllowAutoRedirect = false;
                    request.IgnoreProtocolErrors = true;
                    string auth = request.Get("https://oauth.vk.com/token?scope=nohttps%2Call&client_id=2274003&client_secret=hHbZxrka2uZ6jB1inYsH&2fa_supported=1&lang=ru&device_id=&grant_type=password&username=" + login + "&password=" + pass + "&libverify_support=1").ToString();
                    File.AppendAllText("1.txt", auth);
                    if (auth.Contains("access_token"))
                    {
                        string access_token = Pars(auth, "access_token\":\"", "\"", 0);
                        string user_id = Pars(auth, "user_id\":", ",\"", 0);
                        string secret = Pars(auth, "secret\":\"", "\"", 0);
                        string sig = GetMd5Hash(MD5.Create(), "execute.getFriendsAndLists" + secret);

                        string friend_get = request.Get("https://api.vk.com/method/execute.getFriendsAndLists?access_token=" + access_token + "&sig=" + sig).ToString();
                        txtLog.Text = friend_get;
                    }
                    else if (auth.Contains("username_or_password_is_incorrect"))
                    {
                        MessageBox.Show("Bad");
                    }
                    else
                    {
                        MessageBox.Show("Error");
                    }


but it didn't work for me to get the list of friends using the execute.getFriendsAndLists method. And the problem is not only with him. The problem is that I can't assemble the correct sig ... help guys out, I'm already all sad.
How do I hash in md5 (maybe this is the case. I took the function on the Internet)
Cry
public static string GetMd5Hash(MD5 md5Hash, string input)
        {
            byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
            StringBuilder sBuilder = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }
            return sBuilder.ToString();
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xoo, 2019-01-11
@blood-moon

update

sig = md5("api_id={api_id}method=friends.getrandom={random}timestamp={timestamp}user_id={user_id}{app_secret}")

url = "https://api.vkontakte.ru/api.php?api_id={api_id}&method=friends.get&random={random}&timestamp={timestamp}&sig={sig}&user_id={user_id}"

app_secret - application key, not user
To check, take a hash from
Should work
end update works for me I'm
not very good at C#, I know a little VK api
The documentation says that you also need to pass the API version with the V parameter, you missed it, maybe this is the problem?
And here it is indicated that your type of authorization through https://oauth.vk.com/token requires permission from the administration
Is there any error text? Is the token passed in auth?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question