VkNet Documentation

repository·develop·Indexed 20 days ago

https://github.com/vknet/vk

A .NET library providing a C# wrapper for the VK (VKontakte) API. It allows developers to interact with the VK social network platform, featuring data models such as the App class for application metadata, the Entry class for advertising campaign logs, and the Start class for campaign parameters.

Tokens
1.8K
Snippets
5
Records
7
Agent score
69%

What's inside VkNet

  1. Getting started with VkNet

    develop

    To use the library, follow these steps:

    1. Create a VK Application: Visit vk.ru/editapp?act=create to set up your application credentials.
    2. Authorize: Follow the authorization guide to authenticate your application. Detailed instructions are available in the official authorization documentation.
    3. Call Methods: Once authorized, you can begin using the library's methods. A categorized list of available methods can be found in the method documentation.

    For common issues, refer to the FAQ wiki.

  2. Note on the obsolete IsHtml5App property

    develop

    The IsHtml5App property is marked as [Obsolete]. As of version 5.85, the is_html5_app field is no longer provided in the application object. Instead, you should use the Type property to determine the application type.

    // Obsolete: Use the 'Type' property instead
    [Obsolete("5.85 В объекте приложения больше не приходит поле is_html5_app. Смотрите поле type", false)]
    public bool IsHtml5App { get; set; }
  3. Reference App class properties

    develop

    The App class includes the following properties, mapped from the VK API JSON response:

    PropertyJSON KeyDescription
    IdidApplication identifier (ulong)
    TitletitleApplication name
    Icon278icon_278URI for 278px wide icon
    Icon139icon_139URI for 139px wide icon
    Icon150icon_150URI for 150px wide icon
    Icon75icon_75URI for 75px wide icon
    Icon16icon_16URI for 16px wide icon
    Banner560banner_560URI for 560px wide banner
    Banner1120banner_1120URI for 1120px wide banner
    TypetypeApplication type (AppType?)
    SectionsectionApplication category
    AuthorUrlauthor_urlURL to the author's page
    AuthorIdauthor_idAuthor identifier (ulong?)
    AuthorGroupauthor_groupOfficial group identifier (ulong?)
    MembersCountmembers_countNumber of application members
    PublishedDatepublished_datePublication date (string)
    CatalogPositioncatalog_positionPosition in the catalog (ulong?)
    InternationalinternationalWhether the app is multi-language
    LeaderBoardTypeleaderboard_typeType of leaderboard (LeaderboardTypes)
    GenreIdgenre_idGenre identifier (int?)
    GenregenreGenre name
    PlatformIdplatform_idStore platform identifier (int?)
    IsInCatalogis_in_catalogWhether available in mobile catalog (bool?)
    FriendsfriendsList of friend IDs who installed the app (ReadOnlyCollection<long>)
    InstalledinstalledWhether the app is installed by the current user (bool?)
    ScreenOrientationscreen_orientationSupported screen orientation (ScreenOrientation?)
    MobileControlsTypemobile_controls_typeWebview control display type (MobileControlsType)
    MobileViewSupportTypemobile_view_support_typeMobile view support type (MobileViewSupportType)
    DescriptiondescriptionApplication description
    ScreenNamescreen_nameApp subdomain or screen name
    ScreenshotsscreenshotsCollection of application screenshots (IEnumerable<Photo>)
    PushEnabledpush_enabledWhether push notifications are enabled (bool?)
  4. Use the Entry class for advertising campaign logs

    develop

    The Entry class represents the latest user actions related to an advertising campaign. It is used to deserialize log data containing user interactions, status changes, and session information.

    Key properties include:

    • Date: The timestamp of the action (Unix time).
    • Status: The type of action: 0 for start, 1 for completion, and 2 for user blocking.
    • Uid: The unique identifier of the user.
    • Comment: Textual comment associated with the entry.
    • Aid: The application ID from which the action was performed.
    • TestMode: Indicates if the action was in 0 (working mode) or 1 (test mode).
    • StartDate: The start time of the action (Unix time), specifically used when Status is 1.
    • Sid: The session identifier.
    using VkNet.Model;
    
    // Example of how an Entry object might be used after deserialization
    public void ProcessEntry(Entry entry)
    {
        if (entry.Status == 0)
        {
            Console.WriteLine($"User {entry.Uid} started action at {entry.Date}");
        }
        else if (entry.Status == 1 && entry.StartDate.HasValue)
        {
            Console.WriteLine($"User {entry.Uid} completed action. Started at: {entry.StartDate}");
        }
    }
  5. Use the Start model for advertising campaign parameters

    develop

    The Start class is a data model used to represent the parameters or state when successfully starting an advertising campaign. It maps to the JSON structure required by the VK API for this operation.

    Key properties:

    • VkSid: The advertising campaign session ID (mapped from the JSON key vk_sid).
    • TestMode: The transaction mode. Use 1 for test mode and 0 for real mode (mapped from the JSON key test_mode).
    var startParams = new VkNet.Model.Start
    {
        VkSid = "your_session_id",
        TestMode = 1 // 1 for test mode, 0 for real mode
    };
  6. Use the App class to represent application information

    develop

    The App class in the VkNet.Model namespace is a data model used to represent information about a VK application. It contains metadata such as the application's ID, title, icons, banners, author details, and various technical specifications like screen orientation and mobile control types.

    using VkNet.Model;
    
    // Example of accessing App properties
    public void ProcessApp(App app)
    {
        Console.WriteLine($"App Name: {app.Title}");
        Console.WriteLine($"App ID: {app.Id}");
        Console.WriteLine($"Author URL: {app.AuthorUrl}");
    }