Hi,

Have you tried inspecting the network traffic? Does the request contain the 
extra header?

What's urlfetch?

Cheers,


On Monday, October 31, 2016 at 1:35:00 PM UTC+1, Tahir Rauf wrote:
>
> I am using oauth2 to access a third party API. I can get the access token 
> alright, but when I try to call the API by passing the bearer token in the 
> request headers it gives me 401 (Unauthorized) error.  Although it works 
> well when I try to do it via POSTMAN by passing headers as  (Authorization: 
> Bearer <ACCESS_TOKE>). But it does not work using go.
>
>
> Here is the code sample.
>
>
>         url := "http://api.kounta.com/v1/companies/me.json";
>
>
> var bearer = "Bearer " + <ACCESS TOKEN HERE>
>
>
> req, err := http.NewRequest("GET", url, nil)
>
> req.Header.Add("authorization", bearer)
>
>
> client := urlfetch.Client(context)
>
>
> resp, err := client.Do(req)
>
> if err != nil {
>
> panic(err)
>
> }
>
> defer resp.Body.Close()
>
>
> body, _ := ioutil.ReadAll(resp.Body)
>
> writer.Write([]byte(body)) // Gives 401 Unauthorized error, though same 
> works using POSTMAN
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to