vk_auth
Vk:Auth
Crystal library for getting an Access Token without manually accessing vk.com website from the browser.
access_token
is needed to run most Vk API requests.
Installation
-
Add the dependency to your
shard.yml
:dependencies: vk_auth: github: mamantoha/vk_auth
-
Run
shards install
Usage
require "vk_auth"
Getting a Token
This library supports the Implicit flow way to obtain an OAuth 2.0 access token.
The Vk::Auth
constructor takes one argument - the Vk application ID.
client = Vk::Auth.new(client_id)
The #get_token
method takes the following arguments:
email
: user loginpassword
: user passwordpermissions
: request application permissions
client.get_token(email, password, permissions: ["friends"])
After successful authorization, you can access #access_token
:
if client.authorized?
client.access_token # => NamedTuple(access_token: String, expires_in: String, user_id: String)
access_token = client.token.not_nil!["access_token"]
end
API requests
Note, this shard doesn't provide the functionality to make API requests.
You can use previously obtained access_token
to make API requests.
For example:
require "http/client"
access_token = "user-access-token"
method_name = "users.get"
parameters = "fields=bdate,city,country"
version = "5.131"
lang = "en"
url = "https://api.vk.com/method/#{method_name}?#{parameters}&access_token=#{access_token}&v=#{version}&lang=#{lang}"
resp = HTTP::Client.get(url)
Contributing
- Fork it (https://github.com/mamantoha/vk_auth/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Anton Maminov - creator and maintainer
Repository
vk_auth
Owner
Statistic
- 0
- 1
- 0
- 0
- 2
- 2 months ago
- November 17, 2021
License
MIT License
Links
Synced at
Thu, 07 Nov 2024 04:10:23 GMT
Languages