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


Golang TwitterApi.VerifyCredentials方法代码示例

本文整理汇总了Golang中github.com/ChimeraCoder/anaconda.TwitterApi.VerifyCredentials方法的典型用法代码示例。如果您正苦于以下问题:Golang TwitterApi.VerifyCredentials方法的具体用法?Golang TwitterApi.VerifyCredentials怎么用?Golang TwitterApi.VerifyCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/ChimeraCoder/anaconda.TwitterApi的用法示例。


在下文中一共展示了TwitterApi.VerifyCredentials方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: authenticate

// Authenticate is a function called for every client's new session.
// It manages several important tasks at the start of the session.
// 1.Ask the user for Username and twitter ID.
// 2.Search the DB to find the player if it's not a new one.
// 3.If the player is new there is a subsequence initiated:
// 3.1.Create a new sun with GenerateSun
// 3.2.Choose home planet from the newly created solar sysitem.
// 3.3.Create a reccord of the new player and start comunication.
func authenticate(ws *websocket.Conn) (*entities.Player, *anaconda.TwitterApi, error) {
	var (
		nickname  string
		twitterId string
		err       error
		request   Request
		setupData *entities.SetupData
		player    *entities.Player
		twitter   *anaconda.TwitterApi
	)

	if err = websocket.JSON.Receive(ws, &request); err != nil {
		return nil, nil, err
	}

	if len(request.Username) <= 0 || len(request.TwitterID) <= 0 {
		return nil, nil, errors.New("Incomplete credentials")
	}

	if cfg.Twitter.SecureLogin {
		var ok bool
		anaconda.SetConsumerKey(cfg.Twitter.ConsumerKey)
		anaconda.SetConsumerSecret(cfg.Twitter.ConsumerSecret)
		twitter = anaconda.NewTwitterApi(request.AccessToken, request.AccessTokenSecret)
		if ok, err = twitter.VerifyCredentials(); !ok {
			return nil, nil, err
		}
	}

	serverParamsMessage := response.NewServerParams()
	if err = websocket.JSON.Send(ws, &serverParamsMessage); err != nil {
		return nil, nil, err
	}

	nickname = request.Username
	twitterId = request.TwitterID

	entity, _ := entities.Get(fmt.Sprintf("player.%s", nickname))
	if entity == nil {
		setupData, err = FetchSetupData(ws)
		if err != nil {
			return nil, nil, err
		}
		player = register(setupData, nickname, twitterId, twitter)
	} else {
		player = entity.(*entities.Player)
	}
	return player, twitter, nil
}
开发者ID:WarCluster,项目名称:warcluster-server,代码行数:57,代码来源:auth.go


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