Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Vorkytaka/easyvk-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 

Repository files navigation

EasyVK GoDoc

Package EasyVK provides you simple way to work with VK API.

Installation:

Install:

$ go get -u github.com/solidlsnake/easyvk-go/easyvk

Import:

import "github.com/solidlsnake/easyvk-go/easyvk"

How to work:

Initialize your VK object with your access token.

vk := easyvk.WithToken("token")

Or you can log in by email and password.

// put your email, password, client id and scope
// scope must be a string like "friends,wall"
v, err := easyvk.WithAuth("[email protected]", "pa$$word", "9182736", "friends,wall,photos")
if err != nil {
	// doesn't log in
}

Now you can call method of VK API with your vk variable.

Examples:

Get user profile info:

info, err := vk.Account.GetProfileInfo()

Set user status:

// If you want to update status on your page
// then set ID to 0
userID := 0
ok, err := vk.Status.Set("New status", userID)

Post photo on wall:

id := 0

server, err := vk.Photos.GetWallUploadServer(uint(id))
if err != nil {
	log.Fatal(err)
}

// path to the image
path := "D:/x.png"
uploaded, err := vk.Upload.PhotoWall(server.UploadURL, path)
if err != nil {
	log.Fatal(err)
}

saved, err := vk.Photos.SaveWallPhoto(0, uint(id), uploaded.Photo, uploaded.Hash, "", uploaded.Server, 0, 0)
if err != nil {
	log.Fatal(err)
}

text := "Caption for the post"
photoID := "photo" + fmt.Sprint(saved[0].OwnerID) + "_" + fmt.Sprint(saved[0].ID)

// -id if you post to group wall
x, err := vk.Wall.Post(id, false, true, false, false, false, text, photoID, "", "", 0, 0, 0, 0, 0)
if err != nil {
	log.Fatal(err)
}
fmt.Println(x)

If you need to call method that not done yet:

methodName := "account.banUser"
params := map[string]string{
        "user_id": "1",
}
byteArray, err := vk.Request(methodName, params)
if err != nil {
        
}
// Now work with byteArray.
// Parse it to struct or to interface.

List of finished methods:

About

Simple way to work with VK API

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages