Skip to content

qucals/VK-API

Repository files navigation

VK API Library

Status CodeFactor
Workflow Workflow Workflow
GitHub Issues GitHub Pull Requests License


The easiest C++ library to use for working with the VK API.

📝 Table of Contents

🧐 About

This is a library for easy work with the VK API. It contains all the standard queries that are defined by VK. This makes it easier to access LongPollServer VK.

🏁 Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Steps :

  1. Copy this repository to your computer;
  2. Open terminal in a directory where you copied the repository;
  3. Change a main directory: cd build;
  4. Enter the following command with your replacements: cmake ..;
  5. Build the project by the next command: cmake --build ..

Prerequisites

The library using 2 additional dependencies:

  1. curlpp - A library for working with requests;
  2. json - A library for working with json.

Note that you also can install it by vcpkg on Windows.

Installing

For connection this library to yours you need to follow the next steps:

  1. Copy this repository to your computer;
  2. Open terminal in a directory where you copied the repository;
  3. Change a main directory: cd build;
  4. Enter the following command with your replacements: cmake ..;
  5. Build and install the project by the next command: cmake --build . --target install --config Release;
  6. If building and install is ended successfully you can see there are include and lib's directories in install's directory.

After the above steps you will have a static library and include's files that you can connection to your project.

🎈 Usage

There are two base examples.

Authorization for Bot:

#include "Bot.hpp"

int main(int argc, const char** argv)
{
    std::string access_token = "your_token_there";
    std::string group_id = "your_group_id_there";

    vk::base::bot::Bot bot(group_id);

    if (bot.Auth(access_token) == true) {
        // The further behaviour
    } else {
        // The further behaviour
    }

    return 0;
}

Authorization for User:

#include "User.hpp"

int main(int argc, const char** argv)
{
    std::string app_id = "your_app_id_there";
    std::string app_secure_key = "your_app_secure_key_there";
    std::string login = "your_login_there";
    std::string password = "your_password_there";
    std::string access_token = "your_access_token_there";

    vk::base::user::User user(app_id, app_secure_key);
    
    if(user.Auth(login, password) == true) {
        // The further behaviour
    } else {
        // The further behaviour
    }

    // or

    if (user.Auth(access_token) == true) {
        // The further behaviour
    } else {
        // The further behaviour
    }

    return 0;
}

There are other examples of using this library in the examples directory.

🚀 Deployment

CMake

If you use CMake you make use the find_package instruction. After installing the project you can find vkapiConfig.cmake in the lib/cmake directory. For connection this library to your project you need to add the following code to your cmake file:

    set(CMAKE_CXX_FLAGS " -lcurl")
    set(VKAPI_DIR *path_to_vkapiconfig.cmake*)
    find_package(VKAPI CONFIG REQUIRED)
    target_link_libraries(${PROJECT_NAME} VKAPI::VKAPI)

Replace: *path_to_vkapiconfig.cmake* to the path to directory lib/cmake;

Others

If you use another building system you need to connection include's files and lib file which is located bin\include and lib directories.

⛏️ Built Using

  • CMake - Cross-platform family of tools designed to build

✍️ Authors