Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
github.com/stels-cs/vk-api-tools
go get git@github.com:stels-cs/vk-api-tools.git
github.com/gorilla/websocket потребуется для работы с WebSocket в StreamingAPI, но устанавливать его не обязательно
go get github.com/gorilla/websocket
package main
import (
"github.com/stels-cs/vk-api-tools"
"strconv"
)
type User struct {
Id int `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
func main() {
users := make([]User, 0)
err := VkApi.Exec("users.get", VkApi.P{"user_ids": "2050,andrew"}, &users)
if err != nil {
panic(err)
}
for _, u := range users {
println(u.FirstName + " " + u.LastName + " #" + strconv.Itoa(u.Id))
}
}
Результат:
Катя Лебедева #2050
Андрей Рогозов #6492
package main
import (
"github.com/stels-cs/vk-api-tools"
)
func main() {
res, err := VkApi.Call("users.get", VkApi.P{"user_ids": "2050,avk", "fields": "city"})
if err != nil {
panic(err)
}
print(res.QStringDef("0.first_name", "") + " – ")
println(res.QStringDef("0.city.title", ""))
print(res.QStringDef("1.first_name", "") + " – ")
println(res.QStringDef("1.city.title", ""))
}
Результат:
Катя – Санкт-Петербург
Александр – Москва
Подробнее про VkApi.Response и про QStringDef
Важно! По умолчанию VkApi.Exec и VkApi.Call будут повторят запрос до 30 раз в случае любых сетевых ошибок или если API вернет кодо ошибки: 1, 9, 6, 9, 10, 603 vk.com/dev/errors. Чтобы отключить это посмотрите пример ниже.
package main
import (
"github.com/stels-cs/vk-api-tools"
"strconv"
)
func main() {
token := "3bac432bdcb1234b1...." //API ключ доступа
v := "5.71" //Версия API по умолчанию
retryTimesIfFailed := 0 //Не повторять запросы в случае любых ошибок, можно поставить 5, тогда запрос будет повторен 5 раз в случае ошибок
api := VkApi.CreateApi(token, v, VkApi.GetHttpTransport(), retryTimesIfFailed)
users := make([]struct{
Id int `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}, 0)
err := api.Exec("users.get", VkApi.P{"user_ids": "2050,andrew"}, &users)
if err != nil {
panic(err)
}
for _, u := range users {
println(u.FirstName + " " + u.LastName + " #" + strconv.Itoa(u.Id))
}
}
Результат:
Катя Лебедева #2050
Андрей Рогозов #6492
Метод VkApi.Call и VkApi.Exec могут вернуть три типа ошибок
все остальные типы
- ошибки парсинга json, только для VkApi.ExecStreamingApi_test.go.txt - такой чтобы у вас не регалось на отсутсвие модуля
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.