本文整理匯總了Golang中github.com/ericflo/irlmoji/src/models.DB.UpdateUserAuth方法的典型用法代碼示例。如果您正苦於以下問題:Golang DB.UpdateUserAuth方法的具體用法?Golang DB.UpdateUserAuth怎麽用?Golang DB.UpdateUserAuth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ericflo/irlmoji/src/models.DB
的用法示例。
在下文中一共展示了DB.UpdateUserAuth方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: HandleCreateUserByTwitter
func HandleCreateUserByTwitter(r render.Render, bindErr binding.Errors, userForm models.UserForm, db *models.DB) {
if bindErr.Count() > 0 {
r.JSON(400, JsonErrBinding(bindErr))
return
}
// Build Twitter client
config := &oauth1a.ClientConfig{
ConsumerKey: TWITTER_CONSUMER_KEY,
ConsumerSecret: TWITTER_CONSUMER_SECRET,
}
oauthUser := oauth1a.NewAuthorizedConfig(userForm.TwitterAccessToken,
userForm.TwitterAccessSecret)
client := twittergo.NewClient(config, oauthUser)
// Build request to send to Twitter
req, err := http.NewRequest("GET", "/1.1/account/verify_credentials.json", nil)
if err != nil {
log.Println("Could not build request for Twitter:", err.Error())
r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
}
// Send it
resp, err := client.SendRequest(req)
if err != nil {
log.Println("Error sending request to Twitter:", err.Error())
r.JSON(504, JsonErr("Could not communicate properly with Twitter, "+
"please try again soon."))
return
}
// Parse the response
var result = &twittergo.User{}
if err = resp.Parse(result); err != nil {
log.Println("Error parsing Twitter result:", err.Error(), "Response:",
resp)
r.JSON(504, JsonErr("Got a bad response from Twitter, please try "+
"again soon."))
return
}
user, err := db.GetUserWithId(result.IdStr())
if err == nil {
user, err = db.UpdateUserAuth(user.Id, userForm.TwitterAccessToken,
userForm.TwitterAccessSecret)
if err != nil {
log.Println("Error updating user auth:", err.Error())
r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
return
}
r.JSON(200, map[string]*models.User{"user": user})
return
}
// Now let's create that user, shall we?
user, err = db.CreateUser(
result.IdStr(),
result.ScreenName(),
(*result)["profile_image_url"].(string),
userForm.TwitterAccessToken,
userForm.TwitterAccessSecret,
)
if err != nil {
log.Println("Error creating user:", err.Error())
r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
return
}
r.JSON(200, map[string]*models.User{"user": user})
}