Skip to content

Instantly share code, notes, and snippets.

@Gerifield
Created April 3, 2015 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gerifield/443b88436d3f26fe79f9 to your computer and use it in GitHub Desktop.
Save Gerifield/443b88436d3f26fe79f9 to your computer and use it in GitHub Desktop.
Twitter test client in GO with PIN auth
// TwitterGo
package main
import (
"fmt"
"strconv"
"time"
renurl "net/url"
"github.com/ChimeraCoder/anaconda"
)
func main() {
//fmt.Println("Hello World!")
anaconda.SetConsumerKey(key)
anaconda.SetConsumerSecret(secret)
url, creds, err := anaconda.AuthorizationURL("oob")
if err != nil {
panic(err)
}
fmt.Println("URL: " + url)
var inp string
fmt.Print("PIN: ")
fmt.Scanf("%s", &inp)
tokens, urlValues, err := anaconda.GetCredentials(creds, inp)
if err != nil {
panic(err)
}
fmt.Println(tokens)
fmt.Println(urlValues)
api := anaconda.NewTwitterApi(tokens.Token, tokens.Secret)
/*user, err := api.GetSelf(nil)
if err != nil {
fmt.Println("Error")
return
}
fmt.Println(user.Name)*/
var lastId int64 = 0
for {
v := renurl.Values{}
v.Add("count", "100")
v.Add("since_id", strconv.FormatInt(lastId, 10))
fmt.Println(v)
result, err := api.GetSearch("#ustream OR #yolo", v)
//result, err := api.GetSearch("#ustream", v)
if err != nil {
panic(err)
}
for _, tweet := range result.Statuses {
//fmt.Println(strconv.Itoa(i) + ": " + tweet.Text)
fmt.Println(tweet.IdStr + " " +tweet.User.Name+ ": " + tweet.Text)
if (tweet.Id > lastId) {
lastId = tweet.Id
}
}
//fmt.Println("LastId: ", lastId)
fmt.Println("LastId: " + strconv.FormatInt(lastId, 10))
time.Sleep(5 * time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment