phamngsinh / goauth2

Automatically exported from code.google.com/p/goauth2
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

appengine *http.Client #27

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
How do you assign the appengine *http.Client to transport?

Tried something like this,

c := endpoints.NewContext(r)
transport.Client=func() *http.Client {return urlfetch.Client(c)}

Original issue reported on code.google.com by gert.cuykens@gmail.com on 4 Jan 2014 at 2:33

GoogleCodeExporter commented 8 years ago
tried this also,

var transport = &oauth.Transport{Config: config, Transport:urlfetch.Client(c)}

Original comment by gert.cuykens@gmail.com on 4 Jan 2014 at 3:34

GoogleCodeExporter commented 8 years ago
Maybe I don't understand the question...  to use urlfetch from App Engine, you 
can do something like this:

package example

import (
    "net/http"

    "appengine"
    "appengine/urlfetch"
)

func handler(w http.ResponseWriter, r *http.Request) {
    c := appengine.NewContext(r)
    client := urlfetch.Client(c)

    bucket := "my-bucket"
    filepath := "myfile.txt"
    url := fmt.Sprintf("https://www.googleapis.com/storage/v1beta2/b/%v/o/%v", url.QueryEscape(bucket), url.QueryEscape(filepath))
    rsp, err := client.Get(url)
    if err != nil {
        c.Errorf("unable to client.Get(%v): %v", url, err)
    }
    //...
}

Original comment by gmle...@google.com on 25 Apr 2014 at 3:09