vk

package module
v0.0.0-...-edf3223 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2017 License: MIT Imports: 17 Imported by: 0

README

vk GoDoc

Go package for VKontakte API. It is work in progress and API may change.

VK API version 5.53

TODO

  • add examples
  • implement users.* methods
  • implement friends.* methods
  • add tests

Documentation

Overview

Package vk implements VKontakte API (including OAuth)

Index

Constants

View Source
const (
	// attachment type
	AT_Photo       = "photo"
	AT_Sticker     = "sticker"
	AT_PostedPhoto = "posted_photo"
	AT_Video       = "video"
	AT_Audio       = "audio"
	AT_Doc         = "doc"
	AT_Graffiti    = "graffiti"
	AT_Url         = "url"
	AT_Link        = "link"
	AT_Note        = "note"
	AT_App         = "app"
	AT_Poll        = "poll"
	AT_Page        = "page"
)
View Source
const (
	ErrZero = iota
	ErrUnknown
	ErrAppDis
	ErrUnknownMethod
	ErrIncorrectSignature
	ErrAuthorizeFailed
	ErrTooManyReq
	ErrActDenied
	ErrInvalidReq
	ErrFloodControl
	ErrInternalServer
	ErrTestMode
	ErrTwelve
	ErrThirteen
	ErrCaptcha
	ErrAccDenied
	ErrHTTPAuthorizeFailed
	ErrValidationRequired
	ErrEighteen
	ErrNineteen
	ErrActDeniedNonStandalone
	ErrActOnlyStandalone
	ErrTwentyTwo
	ErrMethodDis
	ErrConfirmRequired
	ErrParamMissing     = 100
	ErrInvalidAppAPIID  = 101
	ErrInvalidUserID    = 113
	ErrInvalidTimestamp = 150
)
View Source
const (
	NotifFollow            = "follow"
	NotifFriendAccepted    = "friend_accepted"
	NotifMention           = "mention"
	NotifMentionComments   = "mention_comments"
	NotifWall              = "wall"
	NotifCommentPost       = "comment_post"
	NotifCommentPhoto      = "comment_photo"
	NotifCommentVideo      = "comment_video"
	NotifReplyComment      = "reply_comment"
	NotifReplyCommentPhoto = "reply_comment_photo"
	NotifReplyCommentVideo = "reply_comment_video"
	NotifReplyTopic        = "reply_topic"
	NotifLikePost          = "like_post"
	NotifLikeComment       = "like_comment"
	NotifLikePhoto         = "like_photo"
	NotifLikeVideo         = "like_video"
	NotifLikeCommentPhoto  = "like_comment_photo"
	NotifLikeCommentVideo  = "like_comment_video"
	NotifLikeCommentTopic  = "like_comment_topic"
	NotifCopyPost          = "copy_post"
	NotifCopyPhoto         = "copy_photo"
	NotifCopyVideo         = "copy_video"
)
View Source
const (
	MsgUnreadOnly  = 1
	MsgNotChat     = 2
	MsgFromFriends = 4
)
View Source
const (
	PostSrc_VK       = "vk"
	PostSrc_Widget   = "widget"
	PostSrc_Api      = "api"
	PostSrc_Rss      = "rss"
	PostSrc_Sms      = "sms"
	PostType_Post    = "post"
	PostType_Suggest = "suggest"
)
View Source
const (
	JT_Join     = "join"
	JT_Unsure   = "unsure"
	JT_Accepted = "accepted"
	JT_Approved = "approved"
	JT_Request  = "request"
)
View Source
const (
	ScopeNotify        = Scope(1)
	ScopeFriends       = Scope(2)
	ScopePhotos        = Scope(4)
	ScopeAudio         = Scope(8)
	ScopeVideo         = Scope(16)
	ScopeDocs          = Scope(131072)
	ScopeNotes         = Scope(2048)
	ScopePages         = Scope(128)
	ScopeStatus        = Scope(1024)
	ScopeOffers        = Scope(32)
	ScopeQuestions     = Scope(64)
	ScopeWall          = Scope(8192)
	ScopeGroups        = Scope(262144)
	ScopeMessages      = Scope(4096)
	ScopeEmail         = Scope(4194304)
	ScopeNotifications = Scope(524288)
	ScopeStats         = Scope(1048576)
	ScopeAds           = Scope(32768)
	ScopeOffline       = Scope(65536)
)

List of known access scopes from https://vk.com/dev/permissions

View Source
const (
	VK_MAX_PHOTOS = 5
	VK_MAX_AUDIOS = 1
	VK_MAX_DOCS   = 1
	VK_MAX_VIDEOS = 1
)
View Source
const (
	UnlinkPhoto = iota
	UnlinkDoc
	UnlinkVideo
	UnlinkAudio
)
View Source
const (
	NameCaseNom = "nom"
	NameCaseGen = "gen"
	NameCaseDat = "dat"
	NameCaseAcc = "acc"
	NameCaseIns = "ins"
	NameCaseAbl = "abl"
)
View Source
const (
	FieldPhotoId         = "photo_id"
	FieldVerified        = "verified"
	FieldBlacklisted     = "blacklisted"
	FieldSex             = "sex"
	FieldBirthDate       = "bdate"
	FieldCity            = "city"
	FieldCountry         = "country"
	FieldHomeTown        = "home_town"
	FieldPhoto50         = "photo_50"
	FieldPhoto100        = "photo_100"
	FieldPhoto200        = "photo_200"
	FieldPhoto200Orig    = "photo_200_orig"
	FieldPhoto400Orig    = "photo_400_orig"
	FieldPhotoMax        = "photo_max"
	FieldPhotoMaxOrig    = "photo_max_orig"
	FieldOnline          = "online"
	FieldLists           = "lists"
	FieldDomain          = "domain"
	FieldHasMobile       = "has_mobile"
	FieldContacts        = "contacts"
	FieldSite            = "site"
	FieldEducation       = "education"
	FieldUniversities    = "universities"
	FieldSchools         = "schools"
	FieldStatus          = "status"
	FieldLastSeen        = "last_seen"
	FieldFollowersCount  = "followers_count"
	FieldCommonCount     = "common_count"
	FieldCounters        = "counters"
	FieldOccupation      = "occupation"
	FieldNickName        = "nickname"
	FieldRelatives       = "relatives"
	FieldRelation        = "relation"
	FieldPersonal        = "personal"
	FieldConnections     = "connections"
	FieldExports         = "exports"
	FieldWallComments    = "wall_comments"
	FieldActivities      = "activities"
	FieldInterests       = "interests"
	FieldMusic           = "music"
	FieldMovies          = "movies"
	FieldTv              = "tv"
	FieldBooks           = "books"
	FieldGames           = "games"
	FieldAbout           = "about"
	FieldQuotes          = "quotes"
	FieldCanPost         = "can_post"
	FieldCanSeeAllPosts  = "can_see_all_posts"
	FieldCanSeeAudio     = "can_see_audio"
	FieldCanWritePrivate = "can_write_private_message"
	FieldTimeZone        = "timezone"
	FieldScreenName      = "screen_name"
	FieldMaidenName      = "maiden_name"
)
View Source
const (
	SexUnknown = 0
	SexFemale  = 1
	SexMale    = 2
)

Variables

View Source
var (
	Debug = false
	// Version of VK API
	Version = "5.53"
	// APIURL is a base to make API calls
	APIURL = "https://api.vk.com/method/"
	// HTTPS defines if use https instead of http. 1 - use https. 0 - use http
	HTTPS = 1
)
View Source
var (
	// NameCases is a list of name cases available for VK
	NameCases = []string{NameCaseNom, NameCaseGen, NameCaseDat, NameCaseAcc, NameCaseIns, NameCaseAbl}
)

Functions

func ClearCaptcha

func ClearCaptcha()

func ElemInSlice

func ElemInSlice(elem string, slice []string) bool

ElemInSlice checks if element is in the slice

func NewDelayer

func NewDelayer(d time.Duration) *delayer

func NewUnlinker

func NewUnlinker(sess *Session, ts ...int) unlinker

func PublicAPI

func PublicAPI(method string, params url.Values, out interface{}) error

func SetCaptcha

func SetCaptcha(id, key string)

func SetServer

func SetServer(s *Session, surl string, gid int) error

SetServer will set the new URL for callback server. And automatically retry till it get status ok or failed. This is blocking call.

func UnlinkAttachments

func UnlinkAttachments(u unlinker, s string) (err error)

Types

type API

type API struct {
	AppID       string
	Secret      string
	Scope       []Scope
	AccessToken string
	Expiry      time.Time
	UserID      string
	UserEmail   string

	Raw []byte
	// contains filtered or unexported fields
}

API holds data to use for communication

func NewAPI

func NewAPI(appID, secret string, scope []Scope, callback string) *API

NewAPI creates instance of API

func (*API) AuthURL

func (api *API) AuthURL(state string, v ...interface{}) string

AuthURL generates URL to authenticate via OAuth. v support option 'responseTyp string' and 'groupId int' (sequence as shown). responseTyp can either be "token" and "code" where default is "code". 'groupId' is to generate URL for group authorization.

func (*API) Authenticate

func (api *API) Authenticate(code string) (*Session, error)

Authenticate with API

func (*API) NewSession

func (api *API) NewSession(tok string) *Session

type AccessToken

type AccessToken struct {
	AccessToken      string        `json:"access_token"`
	ExpiresIn        time.Duration `json:"expires_in"`
	UserID           int           `json:"user_id"`
	UserEmail        string        `json:"email"`
	Error            string        `json:"error"`
	ErrorDescription string        `json:"error_description"`
}

AccessToken response from VK

type ApiList

type ApiList struct {
	Count int         `json:"count"`
	Items interface{} `json:"items"`
}

type Attachment

type Attachment struct {
	Type string          `json:"type"`
	Pl   *Poll           `json:"poll"`
	P    *Photo          `json:"photo"`
	S    *Sticker        `json:"sticker"`
	V    *Video          `json:"video"`
	A    *Audio          `json:"audio"`
	D    *Doc            `json:"doc"`
	G    json.RawMessage `json:"geo"`
}

func GetAttachment

func GetAttachment(r []byte) (*Attachment, error)

Another approach to get the Attachment object from raw bytes string. r is considered given to this method.

func (*Attachment) Audio

func (a *Attachment) Audio() (*Audio, error)

func (*Attachment) Doc

func (a *Attachment) Doc() (*Doc, error)

func (*Attachment) Photo

func (a *Attachment) Photo() (*Photo, error)

func (*Attachment) Poll

func (a *Attachment) Poll() (*Poll, error)

func (*Attachment) Sticker

func (a *Attachment) Sticker() (*Sticker, error)

func (*Attachment) UnmarshalJSON

func (a *Attachment) UnmarshalJSON(b []byte) error

Implement json.Unmarshaler, so the parsing on Post can be parsed directly. TODO: use Decoder struct to implment attachment unmarshal.

func (*Attachment) Video

func (a *Attachment) Video() (*Video, error)

Video will only retrieve the preview image of the video. Only direct authorization is allowed to get the whole video content from VK server.

type AttachmentUploader

type AttachmentUploader interface {
	AddVideo(path, name string) AttachmentUploader
	AddPhoto(path, name string) AttachmentUploader
	AddPhotos([]string) AttachmentUploader
	AddAudio(path, name string) AttachmentUploader
	AddAudios([]string) AttachmentUploader
	AddDoc(path, name string) AttachmentUploader
	AddDocs([]string) AttachmentUploader
	Upload() (string, error)
}

func NewAttachmentsUploader

func NewAttachmentsUploader(sess *Session, gid int) AttachmentUploader

This is optimized for wall posting (comments too) attachments. Video and doc will be uploaded to user's video section and doc section to avoid appear in community video and doc section.

func NewCommunityPMUploader

func NewCommunityPMUploader(user, group *Session, gid int) AttachmentUploader

NewCommunityPMUploader optimize for community PM file upload. Both user and group token are required as group token is used for upload photo through message upload server meanwhile user token is used for doc, video and audio. There isn't any message upload server for video or audio. Message doc upload API only work for non-public page community. Thus it'll not be used. Doc and video will use user token to upload with 0 group_id (default to user section) provide to the http client params. Audio will use user token to upload with group_id (but in the end it'll be uploaded to user section). Photo message upload server don't allow group_id param. Uploaded doc, video and audio will appear on user account doc, video and audio sections respectively and not in group. Use unlinker to unlink them after message with attachments have been sent out and processed properly (video need time to process).

type Audio

type Audio struct {
	ReceiveContent
	Id       int    `json:"id"`
	Owner    int    `json:"owner_id"`
	Artist   string `json:"artist"`
	Title    string `json:"title"`
	Duration int    `json:"duration"` // in sec // TODO: parse to time.Duration
	Url      string `json:"url"`
	Lyrics   int    `json:"lyrics_id"`
	Album    int    `json:"album_id"`
	Genre    int    `json:"genre_id"`
}

type Bool

type Bool bool

Bool is a bool variable parsed from int

func (Bool) MarshalJSON

func (b Bool) MarshalJSON() ([]byte, error)

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(s []byte) error

type CBConfirmCode

type CBConfirmCode struct {
	Code string `json:"code"`
}

CB for callback

type CBServerSettings

type CBServerSettings struct {
	Url string `json:"server_url"`
	Key string `json:"secret_key"`
}

CB for callback

type CBSettings

type CBSettings struct {
	MsgNew     Bool `json:"message_new"`
	WCNew      Bool `json:"wall_reply_new"`
	WCEdit     Bool `json:"wall_reply_edit"`
	BPNew      Bool `json:"board_post_new"`
	BPEdit     Bool `json:"board_post_edit"`
	BPDelete   Bool `json:"board_post_delete"`
	BPRestore  Bool `json:"board_post_restore"`
	PhotoNew   Bool `json:"photo_new"`
	VideoNew   Bool `json:"video_new"`
	AudioNew   Bool `json:"audio_new"`
	PCNew      Bool `json:"photo_comment_new"`
	VCNew      Bool `json:"video_comment_new"`
	MCNew      Bool `json:"market_comment_new"`
	GroupJoin  Bool `json:"group_join"`
	GroupLeave Bool `json:"group_leave"`
	WPNew      Bool `json:"wall_post_new"`
}

CB for callback

type Comment

type Comment struct {
	Id          int           `json:"id"`
	FromId      int           `json:"from_id"`
	Date        int64         `json:"date"`
	Text        string        `json:"text"`
	ReplyToUid  int           `json:"reply_to_uid"`
	ReplyToCid  int           `json:"reply_to_cid"`
	Attachments []*Attachment `json:"attachments"`
	Likes       struct {
		Count     int  `json:"count"`
		UserLikes Bool `json:"user_likes"`
		CanLike   Bool `json:"can_like"`
	} `json:"likes"`
	PostOwnerId int `json:"post_owner_id"`
	PostId      int `json:"post_id"`
}

https://vk.com/dev/comment_object

type Doc

type Doc struct {
	ReceiveContent
	Id        int    `json:"id"`
	OwnerId   int    `json:"owner_id"`
	Title     string `json:"title"`
	Size      int    `json:"size"`
	Ext       string `json:"ext"`
	Url       string `json:"url"`
	Date      int64  `json:"date"`
	Type      int    `json:"type"`
	AccessKey string `json:"access_key"`
}

type EpochTime

type EpochTime time.Time

EpochTime is time in seconds. Use it to successfully parse with json

func (EpochTime) MarshalJSON

func (t EpochTime) MarshalJSON() ([]byte, error)

MarshalJSON unix timestamp strings

func (*EpochTime) UnmarshalJSON

func (t *EpochTime) UnmarshalJSON(s []byte) error

UnmarshalJSON unix timestamp strings

type Error

type Error struct {
	Code       int    `json:"error_code"`
	Msg        string `json:"error_msg"`
	CaptchaSId string `json:"captcha_sid"`
	CaptchaImg string `json:"captcha_img"`
	Redirect   string `json:"redirect_uri"`
}

func (*Error) Error

func (e *Error) Error() string

Implement error interface

type Geo

type Geo struct {
	Type  string `json:"type"`
	Coor  string `json:"coordinates"`
	Place struct {
		Id        int     `json:"id"`
		Title     string  `json:"title"`
		Latitude  float32 `json:"latitude"`
		Longitude float32 `json:"longitude"`
		Created   int64   `json:"created"`
		Icon      string  `json:"icon"`
		Country   string  `json:"country"`
		City      string  `json:"city"`
	} `json:"place"`
	Showmap Bool `json:"showmap"`
}

type GeoPlace

type GeoPlace struct {
	Id    int    `json:"id"`
	Title string `json:"title"`
}

GeoPlace contains geographical information like City, Country

type Group

type Group struct {
	// default fields
	Id          int    `json:"id"`
	Name        string `json:"name"`
	ScreenName  string `json:"screen_name"`
	IsClosed    Bool   `json:"is_closed"`
	IsAdmin     Bool   `json:"is_admin"`
	AdminLvl    int    `json:"admin_level"`
	IsMember    Bool   `json:"is_member"`
	Type        string `json:"type"`
	Photo       string `json:"photo"`
	PhotoMedium string `json:"photo_medium"`
	PhotoBig    string `json:"photo_big"`
	// optional fields
	City    int `json:"city,omitempty"`
	Country int `json:"country,omitempty"`
	Place   struct {
		Pid       int     `json:"pid"`
		Title     string  `json:"title"`
		Latitude  float32 `json:"latitude"`
		Longitude float32 `json:"longitude"`
		Type      string  `json:"type"`
		Country   int     `json:"country"`
		City      int     `json:"city"`
		Address   string  `json:"address"`
	} `json:"place,omitempty"`
	Desc           string          `json:"description,omitempty"`
	Wiki           string          `json:"wiki_page,omitempty"`
	MembersCount   int             `json:"members_count,omitempty"`
	Counters       json.RawMessage `json:"counters,omitempty"` // TODO: counters
	StartDate      int64           `json:"start_date,omitempty"`
	EndDate        int64           `json:"end_date,omitempty"`
	CanPost        Bool            `json:"can_post,omitempty"`
	CanSeeAllPosts Bool            `json:"can_see_all_posts,omitempty"`
	Activity       string          `json:"activity,omitempty"`
	Status         string          `json:"status,omitempty"`
	Contacts       string          `json:"contacts,omitempty"`
}

Group contains community information (https://vk.com/dev/fields_groups)

type GroupJoin

type GroupJoin struct {
	UserId   string `json:"user_id"`
	JoinType string `json:"join_type"`
}

type GroupLeave

type GroupLeave struct {
	UserId string `json:"user_id"`
	Self   Bool   `json:"self"`
}

type GroupLooper

type GroupLooper interface {
	More() (*SmallGroup, error)
	Size() int
}

func NewGroupLoop

func NewGroupLoop(s *SmallGroups) GroupLooper

type IdList

type IdList []int

IdList is a list of comma-separated ids

func (IdList) MarshalJSON

func (l IdList) MarshalJSON() ([]byte, error)

func (IdList) String

func (l IdList) String() string

func (*IdList) UnmarshalJSON

func (l *IdList) UnmarshalJSON(s []byte) error

type Int

type Int int

func (Int) MarshalJSON

func (i Int) MarshalJSON() ([]byte, error)

func (*Int) UnmarshalJSON

func (i *Int) UnmarshalJSON(s []byte) error

type LikeType

type LikeType int
const (
	LikesPost LikeType = iota
	LikesComment
	LikesPhoto
	LikesAudio
	LikesVideo
	LikesNote
	LikesPhotoComment
	LikesVideoComment
	LikesTopicComment
)

func (LikeType) String

func (l LikeType) String() string

type Message

type Message struct {
	Id          int           `json:"id"`
	UserId      int           `json:"user_id"`
	Date        int64         `json:"date"`
	ReadState   Bool          `json:"read_state"`
	Out         Bool          `json:"out"`
	Title       string        `json:"title"`
	Body        string        `json:"body"`
	Attachments []*Attachment `json:"attachments"`
	Emoji       Bool          `json:"emoji"`
	Deleted     Bool          `json:"deleted"`
	Fwd         []*Message    `json:"fwd_messages"`
	G           *Geo          `json:"geo"`
	// for group chat
	ChatId     int    `json:"chat_id"`
	ChatActive []int  `json:"chat_active"`
	UsersCount int    `json:"users_count"`
	AdminId    int    `json:"admin_id"`
	Photo50    string `json:"photo_50"`
	Photo100   string `json:"photo_100"`
	Photo200   string `json:"photo_200"`
}

https://vk.com/dev/message

type Messages

type Messages struct {
	Count int
	Items []*Message
}

https://vk.com/dev/message

type NotifItem

type NotifItem struct {
	Type     string          `json:"type"`
	Date     int64           `json:"date"`
	Parent   json.RawMessage `json:"parent,omitempty"`
	Feedback json.RawMessage `json:"feedback"`
}

func (*NotifItem) FeedbackAsComment

func (n *NotifItem) FeedbackAsComment() (*Comment, error)

func (*NotifItem) FeedbackAsPost

func (n *NotifItem) FeedbackAsPost() (*Post, error)

func (*NotifItem) FeedbackIsComment

func (n *NotifItem) FeedbackIsComment() bool

func (*NotifItem) FeedbackIsPost

func (n *NotifItem) FeedbackIsPost() bool

feedback decode

func (*NotifItem) ParentAsComment

func (n *NotifItem) ParentAsComment() (*Comment, error)

func (*NotifItem) ParentAsPost

func (n *NotifItem) ParentAsPost() (*Post, error)

func (*NotifItem) ParentAsTopic

func (n *NotifItem) ParentAsTopic() (*Topic, error)

func (*NotifItem) ParentIsComment

func (n *NotifItem) ParentIsComment() bool

func (*NotifItem) ParentIsPost

func (n *NotifItem) ParentIsPost() bool

parent decode

type Notifications

type Notifications struct {
	Count    int          `json:"count"`
	Items    []*NotifItem `json:"items"`
	Profiles []User       `json:"profiles"`
	Groups   []Group      `json:"groups"`
	LastV    int64        `json:"last_viewed"`
	NextF    string       `json:"next_from"`
}

type Photo

type Photo struct {
	ReceiveContent
	Id        int    `json:"id"`
	AlbumId   int    `json:"album_id"`
	OwnerId   int    `json:"owner_id"`
	Photo75   string `json:"photo_75"`
	Photo130  string `json:"photo_130"`
	Photo604  string `json:"photo_604"`
	Photo807  string `json:"photo_807"`
	Photo1280 string `json:"photo_1280"`
	Photo2560 string `json:"photo_2560"`
	Width     int    `json:"width"`
	Height    int    `json:"height"`
	Text      string `json:"text"`
	Date      int64  `json:"date"`
	AccessKey string `json:"access_key"`
}

type PhotoObj

type PhotoObj struct {
	Pid        int    `json:"pid"`
	Aid        int    `json:"aid"` // album ID
	OwnerId    int    `json:"owner_id"`
	Src        string `json:"src"`
	SrcBig     string `json:"src_big"`
	SrcSmall   string `json:"src"`
	SrcxXBig   string `json:"src_xbig"`
	SrcxXXBig  string `json:"src_xxbig"`
	SrcxXXXBig string `json:"src_xxxbig"`
	Width      int    `json:"width"`
	Height     int    `json:"height"`
	Text       string `json:"text"`
	Created    int64  `json:"created"`
}

https://new.vk.com/dev/photo

type PlatformInfo

type PlatformInfo struct {
	Time     EpochTime `json:"time"`
	Platform int       `json:"platform"`
}

PlatformInfo contains information about time and platform

type Playlist

type Playlist struct {
	Id    int    `json:"id"`
	Owner int    `json:"owner_id"`
	Title string `json:"title"`
}

type Poll

type Poll struct {
	Id       int    `json:"id"`
	OwnerId  int    `json:"owner_id"`
	Created  int64  `json:"created"`
	Question string `json:"question"`
	Votes    int    `json:"votes"`
	AnswerId int    `json:"answer_id"`
	Answers  []struct {
		Id    int     `json:"id"`
		Text  string  `json:"text"`
		Votes int     `json:"votes"`
		Rate  float32 `json:"rate"`
	} `json:"answers"`
	Anonymous int `json:"anonymous"`
}

type Post

type Post struct {
	Id           int    `json:"id"`
	FromId       int    `json:"from_id"`
	OwnerId      int    `json:"owner_id"`
	Date         int64  `json:"date"`
	PostType     string `json:"post_type"`
	Text         string `json:"text"`
	CanEdit      Bool   `json:"can_edit"`
	CreatedBy    int    `json:"created_by"`
	CanDel       Bool   `json:"can_delete"`
	ReplyOwnerId int    `json:"reply_owner_id"`
	ReplyPostId  int    `json:"reply_post_id"`
	FriendsOnly  int    `json:"friends_only"`
	Comments     struct {
		Count   int  `json:"count"`
		CanPost Bool `json:"can_post"`
	} `json:"comments"`
	Likes struct {
		Count      int  `json:"count"`
		UserLikes  Bool `json:"user_likes"`
		CanLike    Bool `json:"can_like"`
		CanPublish Bool `json:"can_publish"`
	} `json:"likes"`
	Reposts struct {
		Count        int  `json:"count"`
		UserReposted Bool `json:"user_reposted"`
	} `json:"reposts"`
	PostSrc struct {
		Type string `json:"type"`
		Data string `json:"data"`
	} `json:"post_source"`
	Attachments []*Attachment `json:"attachments"`
	G           *Geo          `json:"geo"`
	SignerId    int           `json:"signer_id"`
	CopyHistory []Post        `json:"copy_history"`
	CanPin      Bool          `json:"can_pin"`
	IsPinned    Bool          `json:"is_pinned"`
}

https://vk.com/dev/post

type Receive

type Receive struct {
	// contains filtered or unexported fields
}

func (*Receive) ParseRequest

func (rx *Receive) ParseRequest(r *http.Request) (res *ReceivedResult, err error)

ParseRequest function

type ReceiveContent

type ReceiveContent string

func (ReceiveContent) Content

func (r ReceiveContent) Content() (io.ReadCloser, error)

func (ReceiveContent) String

func (r ReceiveContent) String() string

type ReceivedResult

type ReceivedResult struct {
	Type    string          `json:"type"`
	Object  json.RawMessage `json:"object"`
	GroupId int             `json:"group_id"`
	Secret  string          `json:"secret"`
}

ReceivedResult type

func ParseRequest

func ParseRequest(r *http.Request) (res *ReceivedResult, err error)

func (*ReceivedResult) Audio

func (rr *ReceivedResult) Audio() (*Audio, error)

func (*ReceivedResult) Board

func (rr *ReceivedResult) Board() (*TopicComment, error)

func (*ReceivedResult) GetBoardDelete

func (rr *ReceivedResult) GetBoardDelete() (*TopicDelete, error)

func (*ReceivedResult) GetGroupJoin

func (rr *ReceivedResult) GetGroupJoin() (*GroupJoin, error)

func (*ReceivedResult) GetGroupLeave

func (rr *ReceivedResult) GetGroupLeave() (*GroupLeave, error)

func (*ReceivedResult) PM

func (rr *ReceivedResult) PM() (*Message, error)

func (*ReceivedResult) Photo

func (rr *ReceivedResult) Photo() (*Photo, error)

func (*ReceivedResult) Video

func (rr *ReceivedResult) Video() (*Video, error)

func (*ReceivedResult) WallComment

func (rr *ReceivedResult) WallComment() (*Comment, error)

func (*ReceivedResult) WallPost

func (rr *ReceivedResult) WallPost() (*Post, error)

type Relative

type Relative struct {
	Id   int    `json:"id"`   // negative id describes non-existing users (possibly prepared id if they will register)
	Type string `json:"type"` // like `parent`, `grandparent`, `sibling`
	Name string `json:"name,omitempty"`
}

Relative contains information about relative to the user

type School

type School struct {
	Id         int    `json:"id"`
	Country    int    `json:"country"`
	City       int    `json:"city"`
	Name       string `json:"name"`
	YearFrom   int    `json:"year_from"`
	YearTo     int    `json:"year_to"`
	Class      string `json:"class"`
	TypeStr    string `json:"type_str,omitempty"`
	Speciality string `json:"speciality,omitempty"`
}

School contains information about schools

type Scope

type Scope int

Scope is an access scope from https://vk.com/dev/permissions

func (Scope) String

func (s Scope) String() string

type Session

type Session struct {
	AccessToken string
	UserID      int
	UserEmail   string
}

func NewSession

func NewSession(tok string) *Session

func (*Session) AudioGet

func (s *Session) AudioGet(ids ...int) ([]Audio, error)

func (*Session) AudioGetAlbums

func (s *Session) AudioGetAlbums(owner int, offset, count int) ([]Playlist, error)

func (*Session) AudioGetById

func (s *Session) AudioGetById(ids [][2]int) ([]Audio, error)

func (*Session) AudioGetFromAlbum

func (s *Session) AudioGetFromAlbum(album int, offset, count int) ([]Audio, error)

func (*Session) AudioGetFromUser

func (s *Session) AudioGetFromUser(user int, offset, count int) ([]Audio, error)

func (*Session) AudioSearch

func (s *Session) AudioSearch(qu string, count int, autoCompl, perfOnly bool) ([]Audio, error)

func (*Session) CallAPI

func (s *Session) CallAPI(method string, params url.Values, out interface{}) error

save for multi-goroutines

func (*Session) FriendsGet

func (s *Session) FriendsGet(user int, offset, count int, fields []string, nameCase string) ([]User, error)

func (*Session) Likes

func (s *Session) Likes(t LikeType, id int, likesOptions ...interface{}) (int, error)

func (*Session) MsgsGet

func (s *Session) MsgsGet(out bool, filters int, lastId int) (*Messages, error)

MsgsGet implements method https://vk.com/dev/messages.get

func (*Session) MsgsMarkAsRead

func (s *Session) MsgsMarkAsRead(ids []int) (Bool, error)

MsgsMarkAsRead implements method https://vk.com/dev/messages.markAsRead

func (*Session) NotifGet

func (s *Session) NotifGet(startFrm string, filters []string, start, end int64) (*Notifications, error)

NotifGet implements method https://vk.com/dev/notifications.get. start and end is start_time and end_time field respectively.

func (*Session) NotifMarkAsViewed

func (s *Session) NotifMarkAsViewed() (Bool, error)

NotifMarkAsViewed implements method https://vk.com/dev/notifications.markAsViewed

func (*Session) Unlikes

func (s *Session) Unlikes(t LikeType, id int, likesOptions ...interface{}) (int, error)

func (*Session) UploadAudio

func (s *Session) UploadAudio(path string, gid int) (json.RawMessage, error)

UploadAudio only support upload to user audio at the moment. No API for group audio upload. gid is ignored.

func (*Session) UploadDoc

func (s *Session) UploadDoc(path string) (json.RawMessage, error)

UploadDocs only support upload to user docs at the moment. VK server disallow group docs upload. Only user token will work.

func (*Session) UploadDocToWall

func (s *Session) UploadDocToWall(path string) (json.RawMessage, error)

UploadDocsToWall only support upload to user wall at the moment. VK server disallow group docs upload. Only user token will work.

func (*Session) UploadMultiAlbumPhotos

func (s *Session) UploadMultiAlbumPhotos(ps, ns []string, o, a int) ([]string, error)

func (*Session) UploadMultiAudios

func (s *Session) UploadMultiAudios(ps, ns []string, gid int) ([]string, error)

UploadMultiAudios upload multiple VK audio attachments. It may call multiple times of the API. ps is arary of path string and ns is the array of the file name respectively to ps. ns is optional and can be nil. ns must all end with dot extension format. VK only allow mp3 format to be uploaded as audio type.

func (*Session) UploadMultiDocs

func (s *Session) UploadMultiDocs(ps, ns []string, gid int) ([]string, error)

UploadMultiDocs upload multiple VK doc attachments. It may call multiple times of the API. ps is array of path string and ns is the array of the file name respectively to ps. ns is optional and can be nil. ns must all end with dot extension format.

func (*Session) UploadMultiPMPhotos

func (s *Session) UploadMultiPMPhotos(ps, ns []string, gid int) ([]string, error)

UploadMultiPMPhotos upload multiple VK photo attachments. It may call multiple times of the API. ps is arary of path string and ns is the array of the file name respectively to ps. ns is optional and can be nil. These photos are meant for use in private message. ns must all end with dot extension format.

func (*Session) UploadMultiPhotos

func (s *Session) UploadMultiPhotos(ps, ns []string, owner int) ([]string, error)

UploadMultiPhotos upload multiple VK photo attachments. It may call multiple times of the API. ps is arary of path string and ns is the array of the file name respectively to ps. ns is optional and can be nil. These photos are meant for use in wall though comment can be used too. ns must all end with dot extension format.

func (*Session) UploadMultiVideos

func (s *Session) UploadMultiVideos(ps, ns []string, owner int) ([]string, error)

UploadMultiVideos upload multiple VK video attachments. It may call multiple times of the API. ps is arary of path string and ns is the array of the file name respectively to ps. ns is optional and can be nil. ns must all end with dot extension format.

func (*Session) UploadMultiWallDocs

func (s *Session) UploadMultiWallDocs(ps, ns []string, owner int) ([]string, error)

func (*Session) UploadPhotosToAlbum

func (s *Session) UploadPhotosToAlbum(ss []string, gid, aid int) (json.RawMessage, error)

UploadPhotosToAlbum upload photos to album - either community album or user album. ss are the path to the photo path. gid is the community id if community album is the destination and aid is the album id.

func (*Session) UploadPhotosToPM

func (s *Session) UploadPhotosToPM(ss []string, gid int) (json.RawMessage, error)

func (*Session) UploadPhotosToWall

func (s *Session) UploadPhotosToWall(ss []string, gid int) (json.RawMessage, error)

func (*Session) UploadVideos

func (s *Session) UploadVideos(path string, v url.Values) error

func (*Session) User

func (s *Session) User(fields []string, nameCase string) (User, error)

User returns current user info with call to UsersGet

func (*Session) UsersGet

func (s *Session) UsersGet(userIds []int, fields []string, nameCase string) ([]User, error)

UsersGet implements method http://vk.com/dev/users.get

func (*Session) UsersGetFollowers

func (s *Session) UsersGetFollowers(user int, fields []string, nameCase string, offset, count int) ([]User, error)

UsersGetFollowers implements https://vk.com/dev/users.getFollowers

func (*Session) UsersIsAppUser

func (s *Session) UsersIsAppUser(user int) (bool, error)

UsersIsAppUser implements https://vk.com/dev/users.isAppUser

func (*Session) WallDelete

func (s *Session) WallDelete(id int, ownerOpts ...interface{}) error

func (*Session) WallPin

func (s *Session) WallPin(id int, ownerOpts ...interface{}) error

func (*Session) WallPost

func (s *Session) WallPost(m, a string, ownerOpts ...interface{}) (int, error)

Post wall to either user's wall or user's page (community) wall. Current arg wallOwnerOptions consist of 'idInt int' and 'isCommunity bool' options. idInt is the user ID or community ID. isCommunity is the flag to indicate if the idInt refering a normal user ID or community ID. m is the message that want to be posted on the wall. If wallOwnerOptions is not supplied then this will assume the current user owner of the session token. So, a group token will return error as only user token is valid for wall posting action.

func (*Session) WallPostEdit

func (s *Session) WallPostEdit(id int, m, a string, ownerOpts ...interface{}) error

func (*Session) WallRestore

func (s *Session) WallRestore(id int, ownerOpts ...interface{}) error

func (*Session) WallUnpin

func (s *Session) WallUnpin(id int, ownerOpts ...interface{}) error

type SmallGroup

type SmallGroup struct {
	Id      int    `json:"id"`
	Name    string `json:"name"`
	Type    string `json:"type"`
	IsAdmin Bool   `json:"is_admin"`
}

type SmallGroups

type SmallGroups struct {
	Count int           `json:"count"`
	Items []*SmallGroup `json:"items"`
}

func (*SmallGroups) More

func (s *SmallGroups) More() (*SmallGroup, error)

func (*SmallGroups) Size

func (s *SmallGroups) Size() int

type SmallUser

type SmallUser struct {
	Id         int    `json:"id"`
	ScreenName string `json:"screen_name"`
	FirstName  string `json:"first_name"`
	LastName   string `json:"last_name"`
	Timezone   int    `json:"timezone"`
}

type SmallUsers

type SmallUsers []SmallUser

type Sticker

type Sticker struct {
	ReceiveContent
	Id        int    `json:"id"`
	ProductId int    `json:"product_id"`
	Photo64   string `json:"photo_64"`
	Photo128  string `json:"photo_128"`
	Photo256  string `json:"photo_256"`
	Photo352  string `json:"photo_352"`
	Photo512  string `json:"photo_512"`
	Width     int    `json:"width"`
	Height    int    `json:"height"`
}

type Topic

type Topic struct {
	Id        int    `json:"id"`
	OwnerId   int    `json:"owner_id"`
	Title     string `json:"title"`
	Created   int64  `json:"created"`
	CreatedBy int    `json:"created_by"`
	Updated   int64  `json:"updated"`
	UpdatedBy int    `json:"updated_by"`
	IsClosed  Bool   `json:"is_closed"`
	IsFixed   Bool   `json:"is_fixed"`
	Comments  int    `json:"comments"`
}

https://vk.com/dev/notifications.get

type TopicComment

type TopicComment struct {
	Id           int           `json:"id"`
	FromId       int           `json:"from_id"`
	Date         int64         `json:"date"`
	Text         string        `json:"text"`
	TopicOwnerId int           `json:"topic_owner_id"`
	TopicId      int           `json:"topic_id"`
	Attachments  []*Attachment `json:"attachments"`
	Likes        struct {
		Count     int  `json:"count"`
		UserLikes Bool `json:"user_likes"`
		CanLike   Bool `json:"can_like"`
	} `json:"likes"`
}

https://new.vk.com/dev/callback_api

type TopicDelete

type TopicDelete struct {
	Topic int `json:"topic_id"`
	Id    int `json:"id"`
}

type University

type University struct {
	Id              int    `json:"id"`
	Country         int    `json:"country"`
	City            int    `json:"city"`
	Name            string `json:"name"`
	Faculty         int    `json:"faculty"`
	FacultyName     string `json:"faculty_name"`
	Chair           int    `json:"chair"`
	ChairName       string `json:"chair_name"`
	Graduation      int    `json:"graduation"`
	EducationForm   string `json:"education_form"`
	EducationStatus string `json:"education_status"`
}

University contains information about the university

type UploadAlbumPhotos

type UploadAlbumPhotos struct {
	Server     int    `json:"server"`
	PhotosList string `json:"photos_list"`
	AID        int    `json:"aid"`
	Hash       string `json:"hash"`
}

type UploadAudios

type UploadAudios struct {
	Redirect string `json:"redirect"`
	Server   int    `json:"server"`
	Audio    string `json:"audio"`
	Hash     string `json:"hash"`
}

type UploadDocs

type UploadDocs struct {
	File string `json:"file"`
}

type UploadServer

type UploadServer struct {
	UploadUrl string `json:"upload_url"`
	AlbumId   int    `json:"album_id"`
	UserId    int    `json:"user_id"`
	OwnerId   int    `json:"owner_id"`
	AccessKey string `json:"access_key"`
}

type UploadVideos

type UploadVideos struct {
	Size    int `json:"size"`
	VideoID int `json:"video_id"`
}

type UploadWallPhotos

type UploadWallPhotos struct {
	Server int    `json:"server"`
	Photo  string `json:"photo"`
	Hash   string `json:"hash"`
}

type User

type User struct {
	Id          int    `json:"id"`
	FirstName   string `json:"first_name"`
	LastName    string `json:"last_name"`
	Deactivated string `json:"deactivated"`
	Hidden      Bool   `json:"hidden"`

	PhotoId      string   `json:"photo_id,omitempty"`
	Verified     Bool     `json:"verified,omitempty"`
	Blacklisted  Bool     `json:"blacklisted,omitempty"`
	Sex          int      `json:"sex,omitempty"`
	Birthdate    string   `json:"bdate,omitempty"`
	City         GeoPlace `json:"city,omitempty"`
	Country      GeoPlace `json:"country,omitempty"`
	HomeTown     string   `json:"home_town,omitempty"`
	Photo50      string   `json:"photo_50,omitempty"`
	Photo100     string   `json:"photo_100,omitempty"`
	Photo200     string   `json:"photo_200,omitempty"`
	Photo200Orig string   `json:"photo_200_orig,omitempty"`
	Photo400Orig string   `json:"photo_400_orig,omitempty"`
	PhotoMax     string   `json:"photo_max,omitempty"`
	PhotoMaxOrig string   `json:"photo_max_orig,omitempty"`
	Online       Bool     `json:"online,omitempty"`
	OnlineMobile Bool     `json:"online_mobile,omitempty"`
	OnlineApp    Bool     `json:"online_app,omitempty"`
	Lists        []int    `json:"lists,omitempty"`
	Domain       string   `json:"domain,omitempty"`
	HasMobile    Bool     `json:"has_mobile,omitempty"`
	Contacts     struct {
		Mobile string `json:"mobile_phone,omitempty"`
		Home   string `json:"home_phone,omitempty"`
	} `json:"contacts,omitempty"`
	Site      string `json:"site,omitempty"`
	Education struct {
		University     int    `json:"university,omitempty"`
		UniversityName string `json:"university_name,omitempty"`
		Faculty        int    `json:"faculty,omitempty"`
		FacultyName    string `json:"faculty_name,omitempty"`
		Graduation     int    `json:"graduation,omitempty"`
	} `json:"education,omitempty"`
	Universities   []University `json:"universities,omitempty"`
	Schools        []School     `json:"schools,omitempty"`
	Status         string       `json:"status,omitempty"`
	StatusAudio    interface{}  `json:"status_audio,omitempty"` // TODO: status_audio
	LastSeen       PlatformInfo `json:"last_seen,omitempty"`
	FollowersCount int          `json:"followers_count,omitempty"`
	CommonCount    int          `json:"common_count,omitempty"`
	Counters       struct {
		Albums        int `json:"albums,omitempty"`
		Videos        int `json:"videos,omitempty"`
		Audios        int `json:"audios,omitempty"`
		Photos        int `json:"photos,omitempty"`
		Notes         int `json:"notes,omitempty"`
		Friends       int `json:"friends,omitempty"`
		Groups        int `json:"groups,omitempty"`
		OnlineFriends int `json:"online_friends,omitempty"`
		MutualFriends int `json:"mutual_friends,omitempty"`
		UserVideos    int `json:"user_videos,omitempty"`
		Followers     int `json:"followers,omitempty"`
		UserPhotos    int `json:"user_photos,omitempty"`
		Subscriptions int `json:"subscriptions,omitempty"`
	} `json:"counters,omitempty"`
	Occupation struct {
		Type string `json:"type,omitempty"`
		Id   int    `json:"id,omitempty"`
		Name string `json:"name,omitempty"`
	} `json:"occupation,omitempty"`
	NickName  string     `json:"nickname"`
	Relatives []Relative `json:"relatives,omitempty"`
	Relation  int        `json:"relation,omitempty"` // TODO: constants for relation
	Personal  struct {
		Political  int      `json:"political,omitempty"`
		Langs      []string `json:"langs,omitempty"`
		Religion   string   `json:"religion,omitempty"`
		InspiredBy string   `json:"inspired_by,omitempty"`
		PeopleMain int      `json:"people_main,omitempty"`
		LifeMain   int      `json:"life_main,omitempty"`
		Smoking    int      `json:"smoking,omitempty"`
		Alcohol    int      `json:"alcohol,omitempty"`
	} `json:"personal,omitempty"`
	Connections     interface{} `json:"connections,omitempty"` // TODO: connections
	Exports         interface{} `json:"exports,omitempty"`     // TODO: exports
	WallComments    Bool        `json:"wall_comments,omitempty"`
	Activities      string      `json:"activities,omitempty"`
	Interests       string      `json:"interests,omitempty"`
	Music           string      `json:"music,omitempty"`
	Movies          string      `json:"movies,omitempty"`
	Tv              string      `json:"tv,omitempty"`
	Books           string      `json:"books,omitempty"`
	Games           string      `json:"games,omitempty"`
	About           string      `json:"about,omitempty"`
	Quotes          string      `json:"quotes,omitempty"`
	CanPost         Bool        `json:"can_post,omitempty"`
	CanSeeAllPosts  Bool        `json:"can_see_all_posts,omitempty"`
	CanSeeAudio     Bool        `json:"can_see_audio,omitempty"`
	CanWritePrivate Bool        `json:"can_write_private_message,omitempty"`
	TimeZone        int         `json:"timezone,omitempty"`
	ScreenName      string      `json:"screen_name,omitempty"`
	MaidenName      string      `json:"maiden_name,omitempty"`
}

User contains user information (https://vk.com/dev/fields)

type Video

type Video struct {
	ReceiveContent
	Id          int    `json:"id"`
	OwnerId     int    `json:"owner_id"`
	Title       string `json:"title"`
	Duration    int    `json:"duration"`
	Description string `json:"description"`
	Date        int64  `json:"date"`
	Views       int    `json:"views"`
	Comments    int    `json:"comments"`
	Photo130    string `json:"photo_130"`
	Photo320    string `json:"photo_320"`
	Photo800    string `json:"photo_800"`
	AccessKey   string `json:"access_key"`
	CanEdit     Bool   `json:"can_edit"`
	CanAdd      Bool   `json:"can_add"`
}

type VideoObj

type VideoObj struct {
	Id          int    `json:"id"`
	Vid         int    `json:"vid"`
	OwnerId     int    `json:"owner_id"`
	Title       string `json:"title"`
	Duration    int    `json:"duration"`
	Description string `json:"description"`
	Link        string `json:"link"`
	Photo130    string `json:"photo_130"`
	Photo320    string `json:"photo_320"`
	Photo640    string `json:"photo_640"`
	Date        int64  `json:"date"`
	AddDate     int64  `json:"adding_date"`
	Views       int    `json:"views"`
	Player      string `json:"player"`
}

https://new.vk.com/dev/video_object

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL