Ejemplo n.º 1
0
func (au *Auth) GET(c *kocha.Context) error {
	client := twitter.GetClient()
	callbackUrl := kocha.Getenv("RETWITTER_TWITTER_CALLBACK", "")
	requestToken, url, err := client.GetRequestTokenAndUrl(callbackUrl)
	if err != nil {
		return c.RenderError(500, err, nil)
	}

	c.Session.Set("requestToken.Token", requestToken.Token)
	c.Session.Set("requestToken.Secret", requestToken.Secret)
	return c.Redirect(url, false)
}
Ejemplo n.º 2
0
func Exec() {
	logger.Info("auto retweet start.")

	dbInst := db.Get("default")
	defer func() {
		if err := recover(); err != nil {
			dbInst.Rollback()
		} else {
			dbInst.Commit()
		}
	}()
	if err := dbInst.Begin(); err != nil {
		logger.Error(err)
		panic(err)
	}

	queues := findQueue()
	updateQueueStatus(queues, model.QUEUE_STATUS_LOCKED)

	client := twitter.GetClient()
	for _, queue := range queues {
		accessToken := &oauth.AccessToken{
			Token:  queue.AccessToken,
			Secret: queue.AccessTokenSecret,
		}

		var err error
		switch queue.Action {
		case model.QUEUE_ACTION_RETWEET:
			err = retweet(queue, client, accessToken)
		case model.QUEUE_ACTION_TWEET:
			err = tweet(queue, client, accessToken)
		case model.QUEUE_ACTION_FAVORITE:
			err = favorite(queue, client, accessToken)
		}

		if err != nil {
			logger.Info(queue.Action + " failed [ID:" + queue.TwitterId + "]")
			logger.Error(err)
			queue.FailCount++
			queue.Status = model.QUEUE_STATUS_FAILED
		} else {
			logger.Info(queue.Action + " completed [ID:" + queue.TwitterId + "]")
			queue.Status = model.QUEUE_STATUS_COMPLETED
		}
		updateQueue(queue)
	}

	logger.Info("auto retweet end.")
}
Ejemplo n.º 3
0
func (au *AuthCallback) GET(c *kocha.Context) error {
	oauthVerifier := c.Params.Get("oauth_verifier")
	requestToken := au.GetRequestToken(c)
	if oauthVerifier != "" && requestToken != nil {
		client := twitter.GetClient()
		accessToken, err := client.AuthorizeToken(requestToken, oauthVerifier)
		if err == nil {
			err = model.RegisterUser(accessToken)
		}

		if err != nil {
			return c.RenderError(500, err, nil)
		}
	}

	return c.Redirect("/users", false)
}