Skip to content

elias506/vk-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VK-SDK

Go Report Card GitHub release (latest by date including pre-releases) Lines of code Contributors Go Reference License

Package vk-sdk provides a full generated development kit to work with VKontakte API. The lack of reflection and using easyjson for objects represents a powerful performance. All methods, error codes, objects and responses with provided descriptions are included.

Code was generated by using fork from official vk-api-schema. In other words, the package is easy to maintain and can be comfortably used by consumers because of its comprehensive documentation.

Contributing

We are welcome to new participants of the project. Feel free to create a bug or enhancement issue and new pull request.

Get started

Install:

go get github.com/elias506/vk-sdk

Examples

Look for full in vk-sdk/example/example.go:

Get friends in online:

// Get new client instants with provided token
vk := vk_sdk.NewVK(http.DefaultClient, "<your_token>")

// Get your online friend IDs
req := vk_sdk.Friends_GetOnline_Request{}

resp, apiErr, err := vk.Friends_GetOnline(context.Background(), req, vk_sdk.TestMode())

if err != nil || apiErr != nil {
    log.Fatal()
}

fmt.Println("Online friends IDs:", resp.Response) 

Use Implicit/AuthCode flows to auth:

// Build auth request
authReq := vk_sdk.ImplicitFlowUserRequest{
    ClientID:    "<your_id>", 
    //RedirectURI: "",
    //Display:     nil,
    //Scope:       nil,
    //State:       nil,
    //Revoke:      false,
}

// get redirect url for user
redirectURL := vk_sdk.GetAuthRedirectURL(authReq)

// wait user redirect... 

// get token from redirect url 
token, oAuthErr, err := vk_sdk.GetImplicitFlowUserToken(<user_url>)

if err != nil || oAuthErr != nil {
    log.Fatal()
}

Features

  • LimitClient is http.Client implementation to do requests with provided frequency
  • Generated error codes with description, possible solution and links to subcodes. For example:
// Error_Request Invalid request.
// May contain one of the listed subcodes: [ UserReachedLinkedAccountsLimit, ServiceUuidLinkWithAnotherUser ].
// Solution: Check the request syntax (https://vk.com/dev/api_requests) and used parameters list (it can be found on a method description page).
//  IsGlobal: true
Error_Request ErrorCode = 8
  • Generated access permissions with specification. For example:
// UserPermissionWall Access to standard and advanced methods for the wall.
// Note that this access permission is unavailable for sites (it is ignored at attempt of authorization).
UserPermissionWall AccessPermission = 1 << 13
  • Method descriptions contains Schema specification, token types, additional error code links, and dev.vk.com method link. For example:
// Docs_Delete Deletes a user or community document.
// May execute with listed access token types:
//    [ user ]
// When executing method, may return one of global or with listed codes API errors:
//    [ Error_ParamDocDeleteAccess, Error_ParamDocId ]
//
// https://dev.vk.com/method/docs.delete
func (vk *VK) Docs_Delete(ctx context.Context, req Docs_Delete_Request, options ...Option) (resp Base_Ok_Response, apiErr ApiError, err error) {
	values := make(url.Values, 4+len(options))
	if err = req.fillIn(values); err != nil {
		return
	}
	setOptions(values, options)
	apiErr, err = vk.doReq("docs.delete", ctx, values, &resp)
	return
}
  • Every method contains implies presence context for internal client and additional method option like response language, on/off application test mode and captcha parameters.
  • Enums generate extended name/value from vk-api-shcema. For example:
// Ads_AdCostType Cost type
type Ads_AdCostType int

const (
    Ads_AdCostType_PerClicks               Ads_AdCostType = 0
    Ads_AdCostType_PerImpressions          Ads_AdCostType = 1
    Ads_AdCostType_PerActions              Ads_AdCostType = 2
    Ads_AdCostType_PerImpressionsOptimized Ads_AdCostType = 3
)

Here constant named PerClicks contains int value 0 and so on.

  • Using easyjson to work with api requests/responses
  • There is up-to-date generated vk-api version

Main idea

vk-sdk aims to be user-friendly due to the completeness of the generated code and descriptions, and at the same time to show good executed speed. This package reduces the amount of appeals to official API documentation for validating your request/response structure. Just use right method. Right here.

In addition, code generation allows SDK developers to focus on improving user experience and performance rather than fixing bugs and write large commits. Any code change can be submitted and updated in all places just within a few seconds.

Benchmarks

go-vk-api/vk use simple fields mapping without composition by method and execute with from-the-box speed. In turn SevereCloud/vksdk use reflect package to add input data to request.

lib req/resp size count ns/op B/op allocs/op
vk-sdk medium 220738 5435 9064 60
SevereCloud/vksdk medium 127970 9342 16165 117
go-vk-api/vk medium 220962 5543 8787 64
vk-sdk small 406672 2981 3424 44
SevereCloud/vksdk small 271036 4420 5126 65
go-vk-api/vk small 467112 2506 3129 41

About

Software development kit for VK API

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages