Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VkClient return error #146

Open
Alxdhere opened this issue Aug 22, 2022 · 5 comments
Open

VkClient return error #146

Alxdhere opened this issue Aug 22, 2022 · 5 comments

Comments

@Alxdhere
Copy link

Need to change line:

args.Request.AddParameter("v", "5.74");

5.74 is not supported now. 5.81 is correct value.

@niemyjski
Copy link
Collaborator

Can you please submit a pr

@Alxdhere
Copy link
Author

Excuse me, what is "pr"?

@niemyjski
Copy link
Collaborator

Pull request, also do you have any documentation for the supported versions and api changes?

@Alxdhere
Copy link
Author

Alxdhere commented Aug 23, 2022

I don't have documentation.
I tried to get information about the user using VkClient in the same way as I received information using GoogleClient. But there was an exception.
Then I decided to make requests to the api myself:

    UriBuilder accessUriBuilder = new UriBuilder("https://oauth.vk.com/access_token");
    NameValueCollection accessQueries = HttpUtility.ParseQueryString(accessUriBuilder.Query);
    accessQueries["client_id"] = provider.ClientId;
    accessQueries["client_secret"] = provider.SecretKey;
    accessQueries["redirect_uri"] = redirect.ToString();
    accessQueries["grant_type"] = "authorization_code";
    accessQueries["code"] = code;
    accessUriBuilder.Query = accessQueries.ToString();

    HttpClient httpClient = new HttpClient();
    var accessResponseValue = await httpClient
        .GetStringAsync(accessUriBuilder.Uri.ToString())
        .ConfigureAwait(false);

    var accessResponse = JObject.Parse(accessResponseValue);
    string access_token = accessResponse.GetValue("access_token").Value<string>();
    string user_id = accessResponse.GetValue("user_id").Value<string>();
    string email = accessResponse.GetValue("email").Value<string>();
    
    UriBuilder userInfoUriBuilder = new UriBuilder("https://api.vk.com/method/users.get");
    NameValueCollection userInfoQueries = HttpUtility.ParseQueryString(userInfoUriBuilder.Query);
    userInfoQueries["v"] = "5.74";
    userInfoQueries["access_token"] = access_token;
    userInfoQueries["user_ids"] = user_id;
    userInfoQueries["fields"] = "first_name,last_name,has_photo,photo_max_orig,sex,bdate,phone";
    userInfoUriBuilder.Query = userInfoQueries.ToString();
    
    var userInfoResponseValue = await httpClient
        .GetStringAsync(userInfoUriBuilder.Uri.ToString())
        .ConfigureAwait(false);
    var userInfoResponse = JObject.Parse(userInfoResponseValue);

As a result, I received an error message:
Invalid request: versions below 5.81 are deprecated. Version param should be passed as "v". "version" param is invalid and not supported. For more information go to https://vk.com/dev/constant_version_updates

Fixed 5.74 to 5.81 and it worked! (5.131 is actual)

@niemyjski
Copy link
Collaborator

Thanks for that, if you want to submit a pull request to change the version that would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants