Last active
August 29, 2015 14:02
-
-
Save huandu/86f773cf9bf3c3330508 to your computer and use it in GitHub Desktop.
Facebook Golang SDK: Get location information in a post.
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
// | |
// this code is only a sample to demostrate how to read "place" field in a post. | |
// | |
package main | |
import fb "github.com/huandu/facebook" | |
type Location struct { | |
City string | |
Country string | |
Latitude float | |
Longitude float | |
} | |
type Place struct { | |
Name string | |
Location *Location | |
} | |
type Post struct { | |
Place *Place | |
} | |
func main() { | |
// see sample_graph_data.json for response data structure. | |
post, _ := fb.Get("XXXXXX/feed", fb.Params{ | |
"with": "location", | |
"limit": 1, | |
"access_token": "ABCDEFGHIJK..." | |
}) | |
// get "city" directly. | |
var city string | |
post.DecodeField("place.location.city", &city) | |
// use Post type to extract information. | |
var post Post | |
post.Decode(&post) | |
// advanced trick: decode sub struct. | |
var locationResult Result | |
var location Location | |
post.DecodeField("place.location", &locationResult) | |
locationResult.Decode(&location) | |
// ah yes, following code works fine too. | |
var location2 Location | |
post.DecodeField("place.location", &location2) | |
} |
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
{ | |
"data": [ | |
{ | |
"id": "1111111_22222222222222222", | |
"from": { | |
"id": "1111111", | |
"name": "XXXXXX" | |
}, | |
"story": "XXXXXX was at Melt.", | |
"actions": [ | |
{ | |
"name": "Comment", | |
"link": "https://www.facebook.com/1111111/posts/333333333333333" | |
}, | |
{ | |
"name": "Like", | |
"link": "https://www.facebook.com/1111111/posts/444444444444444" | |
} | |
], | |
"privacy": { | |
"value": "" | |
}, | |
"place": { | |
"id": "153040818058032", | |
"name": "Melt", | |
"location": { | |
"city": "Cincinnati", | |
"country": "United States", | |
"latitude": 39.162578073792, | |
"longitude": -84.539759046744, | |
"state": "OH", | |
"street": "4165 Hamilton Avenue", | |
"zip": "45223" | |
} | |
}, | |
"type": "status", | |
"status_type": "mobile_status_update", | |
"application": { | |
"name": "Facebook for Android", | |
"namespace": "fbandroid", | |
"id": "5555555555" | |
}, | |
"created_time": "2014-03-09T01:03:22+0000", | |
"updated_time": "2014-03-09T01:13:16+0000", | |
"likes": { | |
"data": [ | |
], | |
"paging": { | |
"cursors": { | |
"after": "MTAwMDM0NjE4Nw==", | |
"before": "NTM1OTY1NDE2" | |
} | |
} | |
}, | |
"comments": { | |
"data": [ | |
], | |
"paging": { | |
"cursors": { | |
"after": "MQ==", | |
"before": "MQ==" | |
} | |
} | |
} | |
} | |
], | |
"paging": { | |
"next": "https://graph.facebook.com/v1.0/1111111/feed?limit=1&with=location&until=1394327001" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment