Beispiel #1
0
func (c Twitter) Index() revel.Result {

	var twitterApp = createTwitterOAuth()

	var callbackUrl = fmt.Sprintf("%s:%s/twitter/callback",
		revel.Config.StringDefault("app.baseUrl", "http://localhost"),
		revel.Config.StringDefault("http.port", "9000"))

	requestToken, url, err := twitterApp.GetRequestTokenAndUrl(callbackUrl)

	if err == nil {
		// We received the unauthorized tokens in the OAuth object - store it before we proceed
		revel.TRACE.Println(c.Session["user"])
		user := models.FromJson(c.Session["user"])
		user.RequestToken = requestToken
		c.Session["user"] = models.ToJson(user)

		return c.Redirect(url)
	} else {
		revel.ERROR.Println("Error connecting to twitter:", err)
	}

	c.Flash.Error("Error connecting to twitter!")
	return c.Redirect(App.Index)
}
Beispiel #2
0
func (c App) Search() revel.Result {
	user := models.FromJson(c.Session["user"])
	if user.AccessToken == nil {
		return c.Redirect(App.Index)
	}

	return c.Render(user)
}
Beispiel #3
0
func (c App) Result(keywords string) revel.Result {
	user := models.FromJson(c.Session["user"])
	if user.AccessToken == nil {
		return c.Redirect(App.Index)
	}

	revel.ERROR.Println(keywords)

	return c.Render(user)
}
Beispiel #4
0
func (c Twitter) Callback(oauth_verifier string) revel.Result {
	if oauth_verifier != "" {
		var twitterApp = createTwitterOAuth()
		user := models.FromJson(c.Session["user"])

		// We got the verifier; now get the access token, store it and back to index
		accessToken, err := twitterApp.AuthorizeToken(user.RequestToken, oauth_verifier)

		if err == nil {
			getUserInfo(accessToken, user)
			c.Session["user"] = models.ToJson(user)
			return c.Redirect(App.Search)
		} else {
			revel.ERROR.Println("Error connecting to twitter:", err)
		}
	}

	return c.Redirect(App.Index)
}