关键是 不 登录,设置个人访问令牌并调用client.GetMe。通过查看python驱动程序源代码后,这一点变得很清楚。相关的片段是。
fmt.Println("LoginAsTheBotUser", "Using personal access token") client.AuthToken = mattermost_personal_access_token client.AuthType = model.HEADER_TOKEN if user, resp := client.GetMe(""); resp.Error != nil { println("There was a problem logging into the Mattermost server. Are you sure the access token is valid?") PrintError(resp.Error) } else { fmt.Println(client) botUser = user result = true }上下文。
func LoginAsTheBotUser() bool { fmt.Println("LoginAsTheBotUser") fmt.Println("LoginAsTheBotUser", time.Now()) var result bool = false if mattermost_personal_access_token == "" { fmt.Println("LoginAsTheBotUser", "Getting access token from login with username and password") if user, resp := client.Login(mattermost_user_email, mattermost_user_password); resp.Error != nil { println("There was a problem logging into the Mattermost server. Are you sure ran the setup steps from the README.md?") PrintError(resp.Error) } else { fmt.Println(client) botUser = user result = true } } else { fmt.Println("LoginAsTheBotUser", "Using personal access token") client.AuthToken = mattermost_personal_access_token client.AuthType = model.HEADER_TOKEN if user, resp := client.GetMe(""); resp.Error != nil { //if user, resp := client.Login(mattermost_personal_access_token); resp.Error != nil { println("There was a problem logging into the Mattermost server. Are you sure the access token is valid?") PrintError(resp.Error) } else { fmt.Println(client) botUser = user result = true } } fmt.Println("LoginAsTheBotUser", time.Now()) fmt.Println("LoginAsTheBotUser") return result}


