Beispiel #1
0
func main() {

	flag.Parse()

	if *consumerKey == "" || *consumerSecret == "" {
		fmt.Printf("Get your Twitter token.\n\n")

		fmt.Printf("1. Register your app at http://dev.twitter.com.\n")
		fmt.Printf("2. Run this program with -key $CONSUMER_KEY -secret $CONSUMER_SECRET.\n\n")

		fmt.Printf("Arguments:\n")
		flag.PrintDefaults()
		return
	}

	client := twitter.New(&oauth.Credentials{
		*consumerKey,
		*consumerSecret,
	})

	err := client.Setup()

	if err != nil {
		log.Printf("Error: %s\n", err.Error())
	}
}
Beispiel #2
0
func NewClient() (*twitter.Client, error) {
	conf, err := ReadConfig()
	if err != nil {
		return nil, err
	}
	client := twitter.New(&oauth.Credentials{
		conf.App.User,
		conf.App.Pass,
	})
	client.SetAuth(&oauth.Credentials{
		conf.User.Token,
		conf.User.Secret,
	})
	_, err = client.VerifyCredentials(nil)
	if err == nil {
		return client, nil
	}
	// else User is not setup, let's fix that!
	err = client.Setup()
	if err != nil {
		return nil, err
	}
	// Next we would want to write the credentials
	userToken := client.Auth.Token
	userSecret := client.Auth.Secret
	conf.User.Token = userToken
	conf.User.Secret = userSecret
	WriteConfig(conf)
	return client, nil
}
Beispiel #3
0
func sendTweetForUser(user database.User, message string) {
	client := twitter.New(&oauthSecond.Credentials{
		configuration.ConsumerKey,
		configuration.ConsumerSecret,
	})
	client.SetAuth(&oauthSecond.Credentials{
		user.Twitter_Token,
		user.Twitter_Secret,
	})
	if len(message) > 140 {
		message = message[:140]
	}
	_, err := client.Update(message, nil)
	if err != nil {
		sendProwl("Send Tweet Error", "Couldn't tweet for "+user.Twitter, err)
		return
	}
	db.IncTwitter()
}
Beispiel #4
0
func main() {
	SettingsFile := "../settings.yaml"
	conf, err := yaml.Open(SettingsFile)
	if err != nil {
		panic(err)
	}
	client := twitter.New(&oauth.Credentials{
		to.String(conf.Get("twitter", "app", "key")),
		to.String(conf.Get("twitter", "app", "secret")),
	})
	client.SetAuth(&oauth.Credentials{
		to.String(conf.Get("twitter", "user", "token")),
		to.String(conf.Get("twitter", "user", "secret")),
	})
	_, err = client.VerifyCredentials(nil)

	if err != nil {
		panic(err)
	}
}