Created
April 3, 2015 16:17
-
-
Save Gerifield/443b88436d3f26fe79f9 to your computer and use it in GitHub Desktop.
Twitter test client in GO with PIN auth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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