huandu / facebook

A Facebook Graph API SDK For Go.
https://pkg.go.dev/github.com/huandu/facebook
MIT License
1.34k stars 517 forks source link

fb.Batch is null when added param "include_headers=false" #219

Closed rajuaryan21 closed 1 year ago

rajuaryan21 commented 1 year ago

Hi,

I came across this error while trying to exclude headers from fb response as suggested by facebook here: https://developers.facebook.com/docs/graph-api/batch-requests

See under the sample batch request section. It says "&include_headers=false // Included to remove header information". I tried to add that on fb.Batch call and the result was null.

Could you please check this?

My code:


   batchParams := fb.Params{
    "access_token": accessToken,
    "include_headers": false,
}
params1 := fb.Params{
    "method":       fb.GET,
    "relative_url": "/me?fields=id,name,email",
}
params2 := fb.Params{
    "method":       fb.GET,
    "relative_url": "/me/adaccounts?summary=total_count",
}
params3 := fb.Params{
    "method":       fb.GET,
    "relative_url": "/6919502474734769",
}
results, err := fb.Batch(batchParams, params1, params2, params3)

Thanks. You have created a wonderful library.

huandu commented 1 year ago

I wrote a simple program to reproduce your issue but failed. The results returned by fb.Batch was correct as expected. Have you checked the err? Maybe the err is not nil.

package main

import (
    "fmt"

    fb "github.com/huandu/facebook"
)

func main() {
    accessToken := "A VALID ACCESS TOKEN"

    batchParams := fb.Params{
        "access_token":    accessToken,
        "include_headers": false,
    }
    params1 := fb.Params{
        "method":       fb.GET,
        "relative_url": "/me?fields=id,name,email",
    }
    params2 := fb.Params{
        "method":       fb.GET,
        "relative_url": "/me/adaccounts?summary=total_count",
    }
    params3 := fb.Params{
        "method":       fb.GET,
        "relative_url": "/6919502474734769",
    }
    results, err := fb.Batch(batchParams, params1, params2, params3)
    fmt.Println(results)
    fmt.Println(err)
}
huandu commented 1 year ago

Feel free to reopen this issue if you still have any question.