Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/himidori/golang-vk-api

Methods for VK API
https://github.com/himidori/golang-vk-api

golang vk-api

Last synced: 3 months ago
JSON representation

Methods for VK API

Awesome Lists containing this project

README

        

# VK API wrapper in golang

## Installing

```
go get github.com/himidori/golang-vk-api
```

## Authorizing using username and password

```go
client, err := vkapi.NewVKClient(vkapi.DeviceIPhone, "username", "password", true)
```

## Authorizing using access token

```go
client, err := vkapi.NewVKClientWithToken("token", nil, true)
```

## Listening longpoll events

```go
// listening received messages
client.AddLongpollCallback("msgin", func(m *vkapi.LongPollMessage) {
fmt.Printf("new message received from uid %d\n", m.UserID)
})

// listening deleted messages
client.AddLongpollCallback("msgdel", func(m *vkapi.LongPollMessage) {
fmt.Printf("message %d was deleted\n", m.MessageID)
})

// listening sent messages
client.AddLongpollCallback("msgout", func(m *vkapi.LongPollMessage) {
fmt.Printf("sent message to uid %d\n", m.UserID)
})

// listening read messages
client.AddLongpollCallback("msgread", func(m *vkapi.LongPollMessage) {
fmt.Printf("message %d was read\n", m.MessageID)
})

// listening users online
client.AddLongpollCallback("msgonline", func(m *vkapi.LongPollMessage) {
fmt.Printf("user %d is now online\n", m.UserID)
})

// starting
client.ListenLongPollServer()
```