本文整理汇总了Golang中code/google/com/p/goauth2/oauth.Token.AccessToken方法的典型用法代码示例。如果您正苦于以下问题:Golang Token.AccessToken方法的具体用法?Golang Token.AccessToken怎么用?Golang Token.AccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/google/com/p/goauth2/oauth.Token
的用法示例。
在下文中一共展示了Token.AccessToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: people
// people fetches the list of people user has shared with this app
func people(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
//client := urlfetch.Client(c)
session, err := store.Get(r, "sessionName")
if err != nil {
c.Infof("error fetching session: %v", err)
serveAppError(c, w, &appError{err, "Error fetching session", 500})
return
}
token := session.Values["accessToken"]
// Only fetch a list of people for connected users
if token == nil {
m := "Current user not connected"
serveAppError(c, w, &appError{errors.New(m), m, 401})
return
}
t := &oauth.Transport{Config: config,
Transport: &urlfetch.Transport{Context: c},
}
tok := new(oauth.Token)
tok.AccessToken = token.(string)
t.Token = tok
service, err := plus.New(t.Client())
if err != nil {
serveAppError(c, w, &appError{err, "Create Plus Client", 500})
return
}
// Get a list of people that this user has shared with this app
people := service.People.List("me", "visible")
peopleFeed, err := people.Do()
if err != nil {
m := "Failed to refresh access token"
if err.Error() == "AccessTokenRefreshError" {
serveAppError(c, w, &appError{errors.New(m), m, 500})
return
}
serveAppError(c, w, &appError{err, m, 500})
return
}
w.Header().Set("Content-type", "application/json")
err = json.NewEncoder(w).Encode(&peopleFeed)
if err != nil {
serveAppError(c, w, &appError{err, "Convert PeopleFeed to JSON", 500})
}
}
示例2: people
func people(w http.ResponseWriter, r *http.Request) *appError {
log.Printf("Responding to request %s with people handler", r.URL.Path)
session, err := store.Get(r, "DigitalCampusSession")
if err != nil {
log.Println("error fetching session:", err)
return &appError{err, "Error fetching session", http.StatusInternalServerError}
}
token := session.Values["accessToken"]
// Only fetch a list of people for connected users
if token == nil {
m := "Current user not connected"
return &appError{errors.New(m), m, http.StatusUnauthorized}
}
// Create a new authorized API client
t := &oauth.Transport{Config: config}
tok := new(oauth.Token)
tok.AccessToken = token.(string)
t.Token = tok
service, err := plus.New(t.Client())
if err != nil {
return &appError{err, "Create Plus Client", http.StatusInternalServerError}
}
// Get a list of people that this user has shared with this app
people := service.People.List("me", "visible")
peopleFeed, err := people.Do()
if err != nil {
m := "Failed to refresh access token"
if err.Error() == "AccessTokenRefreshError" {
return &appError{errors.New(m), m, http.StatusInternalServerError}
}
return &appError{err, m, http.StatusInternalServerError}
}
w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(&peopleFeed)
if err != nil {
return &appError{err, "Convert PeopleFeed to JSON", http.StatusInternalServerError}
}
log.Printf("Successfully handled request %s", r.URL.Path)
return nil
}