L
L
linuxoid_inrus2020-10-24 20:01:55
go
linuxoid_inrus, 2020-10-24 20:01:55

How to get an answer from VK?

I want to get post id and other data like isPinned and so on

package main

import (
  "encoding/json"
  "fmt"
  "io/ioutil"
  "net/http"
  "os"
)

func main(){
  var ownerID int
  fmt.Println("Введите ID группы(86529522): ")
  fmt.Fscan(os.Stdin, &ownerID)
  res, err := http.Get("https://api.vk.com/method/wall.get?owner_id=--86529522&count=2&filter=owner&access_token=token&v=5.120")
  if err != nil {
    fmt.Println("Error!")
  }

  bodyBytes, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
  }

  var a map[string]interface{}
  json.Unmarshal(bodyBytes, &a)
  for item := range a["response"].(map[string]interface{})["items"].([]interface{}) {
    fmt.Println(item)
  }


}


Mistake:
Введите ID группы(86529522):
1
panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 1 [running]:
main.main()
        C:/GoLangProjects/VKLastPost/main.go:27 +0x445
exit status 2

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question