项目作者: dimonchik0036

项目描述 :
VK SDK | VKontakte wrapper for standalone apps
高级语言: Go
项目地址: git://github.com/dimonchik0036/vk-api.git
创建时间: 2017-06-18T15:45:05Z
项目社区:https://github.com/dimonchik0036/vk-api

开源协议:MIT License

下载






# VK API? GO!
Build Status
GoDoc
Language
License

Work with Vkontakte API for StandAlone application on The Go Programming Language.

# Usage / Installation

Installation

go get -u github.com/Dimonchik0036/vk-api

Example

Displays incoming messages. If this is a “/start”, then a “Hello!” message will be sent.

  1. package main
  2. import (
  3. "github.com/dimonchik0036/vk-api"
  4. "log"
  5. )
  6. func main() {
  7. //client, err := vkapi.NewClientFromLogin("<username>", "<password>", vkapi.ScopeMessages)
  8. client, err := vkapi.NewClientFromToken("<access_token>")
  9. if err != nil {
  10. log.Panic(err)
  11. }
  12. client.Log(true)
  13. if err := client.InitLongPoll(0, 2); err != nil {
  14. log.Panic(err)
  15. }
  16. updates, _, err := client.GetLPUpdatesChan(100, vkapi.LPConfig{25, vkapi.LPModeAttachments})
  17. if err != nil {
  18. log.Panic(err)
  19. }
  20. for update := range updates {
  21. if update.Message == nil || !update.IsNewMessage() || update.Message.Outbox(){
  22. continue
  23. }
  24. log.Printf("%s", update.Message.String())
  25. if update.Message.Text == "/start" {
  26. client.SendMessage(vkapi.NewMessage(vkapi.NewDstFromUserID(update.Message.FromID), "Hello!"))
  27. }
  28. }
  29. }

Technical Details

  • API version 5.67.