Created
June 9, 2014 03:52
-
-
Save aroman/02123c0c6604d99e58ba 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
package main | |
import ( | |
"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) { | |
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 | |
} | |
for _, post := range posts { | |
fmt.Println(post.CreatedTime) | |
} | |
u, _ := netUrl.Parse(paging.Next) | |
path_without_version_prefix := u.Path[len("/v2.0"):] | |
next := path_without_version_prefix + "?" + u.RawQuery | |
processPosts(next) | |
} | |
func main () { | |
fb.Version = "v2.0" | |
processPosts("/163844093817909/feed"); | |
// processPosts("/163844093817909/feed?fields=created_time&limit=10"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment