Golang Facebook Graph API应用引擎

I'm using huandu/facebook for Golang to access the FB API. https://github.com/huandu/facebook

This works really well locally but when I try to run from the Google App Engine environment, I can't get it to run.

I used this code locally:

res, err := fb.Get("/me", fb.Params{
        "fields": "id,first_name,last_name,name",
        "access_token": usertoken,
    })

In the documentation (link above) they do mention the App Engine environment but I can'f figure out how to ge this to work with the fb.Get convention.

Thanks.

Edit

Almost got it to work!:

// create a global App var to hold app id and secret.
var globalApp = fb.New("<appId>", "<appSecret>")

session := globalApp.Session(usertoken)  //User token here
context := appengine.NewContext(r)  //Not sure what r should be...
session.HttpClient = urlfetch.Client(context)

res, err := session.Get("/me", nil)

if err := json.NewEncoder(w).Encode(res); err != nil {
    panic(err)
}

If I do this I get back the Id and name. Now all I need to do is request the other parameters. Do I do this in the r parameter to the app engine context?

To answer the last question asked, the appengine.NewContext(r) function takes a *http.Request as a parameter, but this refers to the current request, the one your code is executing in. You can use r.URL.Query() if you wanted to get the query parameters that were sent to this request.

If you want to send parameters in another request, like the one to the Facebook API, you can include them directly in the URL you pass to session.Get(). You can use url.Values.Encode if you want to build a query string from a map of values. If you need to make a request using a method other than GET, such as to an API method that expects JSON, you can use http.NewRequest eg.

session.HttpClient = urlfetch.Client(context)
request, err := http.NewRequest("PUT", url, strings.NewReader("{ "someProperty": 1234 }"))
response, err := session.Do(request)