0.01
Low commit activity in last 3 years
No release in over a year
VKontakte API Client for Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 2.8, >= 2.8.0
~> 1.7, >= 1.7.0
 Project Readme

Vkontakte Client

Gem Version

Ruby library for authorization of client applications and for access to the VK API

Installing

Add to your Gemfile:

gem 'vkontakte_client'

Then bundle install

Usage

require 'vkontakte_client'

Application registration

You must register your application in order to use all the capabilities of API VKontakte.

Open the page “Managed apps” in the left menu, then press “Create an app”. You will be directed to the page https://vk.com/editapp?act=create.

You need to choose Standalone-app.

After confirming the action, you will be redirected to the page with information about the app. Open the page "Settings" in the left-hand menu and you will see the field "ID applications", in which a number will be located. For example, 5490057. This number is the application identification, a.k.a. API_ID, APP_ID, client_id, and you will need it for your future work.

Initialize Vkontakte client

With client authorization, the access key to the API access_token. The constructor takes only one argument - the VK application ID - CLIENT_ID.

vk = Vkontakte::Client.new(CLIENT_ID)

Login and password authorization

In general, for API identification, a special access key is used which is called access_token. This token is a string of numbers and Latin letters which you send to the server along with the request.

This library supports the Implicit flow way to obtain an OAuth 2.0 access key: th 2.0:

The login! method takes the following arguments:

vk.login!(email, pass, permissions: 'friends')

API Requests

After successful authorization, you can make requests to the API using the method name from the API function list.

The parameters of the corresponding API method are passed as Hash. Note that a method like friends.get needs to be passed as friends_get.

vk.api.friends_get(fields: 'online', order: 'name', name_case: 'dat')

To avoid errors, you can pre-check the status of the user using the account.getInfo method.

vk.api.account_getInfo

Token Authorization

It is useful to save the received access_token (and, if necessary, the user_id) to reuse them

access_token = vk.access_token
user_id = vk.user_id
api = Vkontakte::API.new(access_token)
api.friends_get(fields: 'online', order: 'name', name_case: 'dat')

Contributing

  1. Fork it (https://github.com/mamantoha/vkontakte_client/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

Copyright: 2010-2023 Anton Maminov (anton.maminov@gmail.com)

This library is distributed under the MIT license. Please see the LICENSE file.