Created
June 9, 2014 04:40
-
-
Save aroman/c15bddba690b6de863b2 to your computer and use it in GitHub Desktop.
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
// usage: go run demo.go OR go run demo.go <number> | |
package main | |
import ( | |
"os" | |
"fmt" | |
netUrl "net/url" | |
fb "github.com/huandu/facebook" | |
) | |
const ACCESS_TOKEN = "<get one here https://developers.facebook.com/tools/explorer>" | |
type Post struct { | |
Id string `facebook:",required"` | |
Message string | |
CreatedTime string | |
} | |
type Paging struct { | |
Previous, Next string | |
} | |
func processPosts (url string, total int) int { | |
fmt.Println(url) | |
res, err := fb.Get(url, fb.Params{ | |
"access_token": ACCESS_TOKEN, | |
}) | |
if (err != nil) { | |
panic(err) | |
} | |
var posts []Post | |
var paging Paging | |
res.DecodeField("data", &posts) | |
res.DecodeField("paging", &paging) | |
if (len(posts) == 0) { | |
return total | |
} | |
u, _ := netUrl.Parse(paging.Next) | |
path_without_version_prefix := u.Path[len("/v2.0"):] | |
next := path_without_version_prefix + "?" + u.RawQuery | |
return processPosts(next, total + len(posts)) | |
} | |
func main () { | |
fb.Version = "v2.0" | |
limit := "25" | |
if (len(os.Args) > 1 ) { | |
limit = os.Args[1] | |
} | |
total := processPosts("/163844093817909/feed?fields=created_time&limit=" + limit, 0) | |
fmt.Println("Total was", total); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment