I was trying to extract FB user info, feed, etc. with Result.DecodeField after a batch request, by using huandu/facebook Golang FB api. Below is the simplified version with a single request in a batch.
I was blocked by this for a whole day. Deep appreciate if you can help check this problem!
code:
type User struct {
Id string `json:"id" facebook:"id"`
Name string `json:"name" facebook:"name"`
}
func batchRequests() {
paramsId := fb.Params{
"method": fb.GET,
"relative_url": "me",
}
results, errBatch := pSession.BatchApi(paramsId)
if errBatch != nil {
fmt.Println("Batch api error:", errBatch.Error())
return
}
fmt.Println("Results[0]:", results[0])
var user User
if err := results[0].DecodeField("body", &user); err != nil {
fmt.Println("Decode user err:", err.Error())
} else {
fmt.Println("user", res0)
}
return
}
Debug msg:
Results[0]: map[code:200 headers:[map[name:Last-Modified value:2014-05-26T02:20:09+0000] map[name:Facebook-API-Version value:v2.0] map[name:ETag value:"53abd9d236bfbd61662d1139e66983f8d0220d1e"] map[name:Content-Type value:text/javascript; charset=UTF-8] map[name:Pragma value:no-cache] map[name:Access-Control-Allow-Origin value:*] map[name:Cache-Control value:private, no-cache, no-store, must-revalidate] map[name:Expires value:Sat, 01 Jan 2000 00:00:00 GMT]] body:{"id":"10152276269XXXXXX","first_name":"XXXX","gender":"male","last_name":"XXXX","link":"https://www.facebook.com/app_scoped_user_id/1015227626XXXXXX/","locale":"zh_TW","name":"XXXXXX","timezone":8,"updated_time":"2014-05-26T02:20:09+0000","verified":true}]
Decode user err: field 'body' is not a json object in result.