Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "os"
- "flag"
- "fmt"
- "github.com/go-resty/resty"
- "encoding/json"
- //"errors"
- "time"
- //"strconv"
- )
- var token string
- type RequestParams map[string]string
- func main() {
- flag.Parse()
- args := flag.Args()
- if len(args) < 1 {
- fmt.Println("Usage: ./vk <token>")
- os.Exit(1)
- }
- token = args[0]
- params := make(RequestParams, 300)
- params["album_id"] = "profile"
- resp, err := CallMethod("photos.get", params)
- if err != nil {
- fmt.Println("ERROR")
- os.Exit(1)
- }
- type JSONBody struct {
- Response struct {
- Count int `json:"count"`
- Items []struct {
- PhotoID int `json:"id"`
- } `json:"items"`
- } `json:"response"`
- }
- var body JSONBody
- json.Unmarshal(resp, &body);
- if len(body.Response.Items) == 0 {
- fmt.Println("PhotoID: undefined")
- os.Exit(1)
- }
- msg := fmt.Sprintf("%d", body.Response.Items[0].PhotoID)
- fmt.Println(msg)
- for i := 0; i < 100; i++ {
- params["photo_id"] = msg
- _, err := CallMethod("photos.delete", params)
- if err != nil {
- fmt.Println("ERROR photos.delete")
- }
- _, err1 := CallMethod("photos.restore", params)
- if err1 != nil {
- fmt.Println("ERROR photos.restore")
- }
- fmt.Println("Avatar must not clickable!")
- time.Sleep(100)
- }
- }
- func CallMethod(method string, params RequestParams) ([]byte, error) {
- params["access_token"] = token
- params["lang"] = "ru" // or..
- params["v"] = "5.60"
- resp, _ := resty.R().
- SetQueryParams(params).
- Get("https://api.vk.com/method/" + method)
- type JSONBody struct {
- Error map[string]interface{} `json:"error"`
- }
- var body JSONBody
- json.Unmarshal(resp.Body(), &body);
- return resp.Body(), nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement