当前位置: 首页>>代码示例>>Golang>>正文


Golang Token.AccessToken方法代码示例

本文整理汇总了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})
	}
}
开发者ID:powerje,项目名称:gplus-quickstart-go,代码行数:53,代码来源:main.go

示例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
}
开发者ID:novaroma,项目名称:digitalcampus,代码行数:42,代码来源:main.go


注:本文中的code/google/com/p/goauth2/oauth.Token.AccessToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。