Skip to content

Instantly share code, notes, and snippets.

@QuynhVir
Created January 17, 2019 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QuynhVir/572602159d3505348d90950f349cf917 to your computer and use it in GitHub Desktop.
Save QuynhVir/572602159d3505348d90950f349cf917 to your computer and use it in GitHub Desktop.
Facebook Graph API and Go http request example
package main
import (
"fmt"
"net/http"
"io/ioutil"
"encoding/json"
)
type Page struct {
Name string `json:"name"`
Id string `json:"id"`
CreatedTime string `json:"created_time"`
}
type Cursor struct {
Before string `json:"before"`
After string `json:"after"`
}
type Response struct {
Data []Page `json:"data"`
Paging struct {
Cursor `json:"cursors"`
Next string `json:"next"`
}
}
func main() {
access_token := ""
resp, err := http.Get("https://graph.facebook.com/v3.2/me/likes?access_token=" + access_token)
if err != nil {
panic(err)
}
defer resp.Body.Close()
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
var response Response
json.Unmarshal([]byte(bodyBytes), &response)
for _, v := range response.Data {
fmt.Println(v.Id)
}
fmt.Println(response.Paging.Next)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment