Created
January 17, 2019 18:34
-
-
Save QuynhVir/572602159d3505348d90950f349cf917 to your computer and use it in GitHub Desktop.
Facebook Graph API and Go http request example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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