Пример #1
0
func NewAccount() *Account {
	credential := auth.CredentialByClientName("Twitter for Mac")
	accessToken := auth.Authenticate(credential)

	account := &Account{
		ConsumerKey:       credential.ConsumerKey,
		ConsumerSecret:    credential.ConsumerSecret,
		AccessToken:       accessToken.Token,
		AccessTokenSecret: accessToken.Secret,
		ScreenName:        accessToken.AdditionalData["screen_name"],
	}
	return account
}
Пример #2
0
func authenticate(options *Options) {
	var credential *auth.Credential

	if len(options.ConsumerKey) > 0 && len(options.ConsumerSecret) > 0 {
		credential = &auth.Credential{
			ConsumerKey:    options.ConsumerKey,
			ConsumerSecret: options.ConsumerSecret,
		}
	} else if len(options.ClientName) > 0 {
		credential = auth.CredentialByClientName(options.ClientName)
	} else {
		credential = auth.DefaultCredential()
	}

	accessToken := auth.Authenticate(credential)
	println("CONSUMER_KEY        :", credential.ConsumerKey)
	println("CONSUMER_SECRET     :", credential.ConsumerSecret)
	println("ACCESS_TOKEN        :", accessToken.Token)
	println("ACCESS_TOKEN_SECRET :", accessToken.Secret)
}