本文整理匯總了Golang中github.com/ChimeraCoder/anaconda.TwitterApi類的典型用法代碼示例。如果您正苦於以下問題:Golang TwitterApi類的具體用法?Golang TwitterApi怎麽用?Golang TwitterApi使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了TwitterApi類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetHomeTimeline
// 自分のTimelineを表示する。
func GetHomeTimeline(api *anaconda.TwitterApi, v url.Values) {
tweets, err := api.GetHomeTimeline(v)
check(err)
for _, tweet := range tweets {
PrintTweet(tweet)
}
}
示例2: postImageTweet
func postImageTweet(api *anaconda.TwitterApi, gifFile string, t *anaconda.Tweet) error {
// Post
data, err := ioutil.ReadFile(gifFile)
if err != nil {
return err
}
mediaResponse, err := api.UploadMedia(base64.StdEncoding.EncodeToString(data))
if err != nil {
return err
}
v := url.Values{}
v.Set("media_ids", strconv.FormatInt(mediaResponse.MediaID, 10))
v.Set("in_reply_to_status_id", t.IdStr)
tweetString := fmt.Sprintf("@%s here are your fireworks", t.User.ScreenName)
_, err = api.PostTweet(tweetString, v)
if err != nil {
return err
} else {
// fmt.Println(result)
}
return nil
}
示例3: PublishTweet
func PublishTweet(article *Article, replyToId string, api *anaconda.TwitterApi) (string, error) {
msg := twitterize(article)
_, err := api.PostTweet(msg, url.Values{
"in_reply_to_status_id": []string{replyToId},
})
return msg, err
}
示例4: fetchStats
// Fetch stats from Twitter and store it for display by the web interface.
func fetchStats(api *anaconda.TwitterApi) error {
handles := strings.Join(democrats, ",") + "," + strings.Join(republicans, ",")
users, err := api.GetUsersLookup(handles, url.Values{})
if err != nil {
return err
}
t := make([]TwitterInfo, len(users))
for i, u := range users {
t[i].Name = u.Name
t[i].Image = u.ProfileImageURL
t[i].Followers = u.FollowersCount
t[i].Tweets = u.StatusesCount
for _, d := range democrats {
if u.ScreenName == d {
t[i].Democrat = true
break
}
}
}
sort.Sort(ByFollowers(t))
stats.Put(t)
return nil
}
示例5: fetchTwitterFriends
// Returns a slice with twitter ids of the given user's friends
func fetchTwitterFriends(screenName string, api *anaconda.TwitterApi) ([]string, error) {
if api == nil {
// Let's just pretend he has no friends, because we can't actually ask
// Twitter about it
return []string{}, nil
}
v := url.Values{}
v.Set("count", "100")
v.Set("cursor", "-1")
v.Set("screen_name", screenName)
friendsIds, err := api.GetFriendsIds(v)
if err != nil {
return nil, err
}
friends, err := api.GetUsersLookupByIds(friendsIds.Ids, url.Values{})
if err != nil {
return nil, err
}
var friendsNames []string
for _, friend := range friends {
friendsNames = append(friendsNames, friend.ScreenName)
}
return friendsNames, nil
}
示例6: blockUser
// Block a user, and tweet a notification of why they were blocked
func blockUser(tweet anaconda.Tweet, ruleName string, cfg *Config, api *anaconda.TwitterApi) {
// Block the user from the main account
user, err1 := api.BlockUserId(tweet.User.Id, nil)
if err1 != nil {
log.Fatalf("Failed to block user: %s", err1)
}
// Let them know via the notification account
anaconda.SetConsumerKey(cfg.Auth2.ConsumerKey)
anaconda.SetConsumerSecret(cfg.Auth2.ConsumerSecret)
api2 := anaconda.NewTwitterApi(cfg.Auth2.AccessToken, cfg.Auth2.AccessTokenSecret)
// TODO: Make this work...
params := url.Values{}
params.Set("InReplyToStatusID", tweet.IdStr)
params.Set("InReplyToStatusIdStr", tweet.IdStr)
tweet2, err2 := api2.PostTweet("@"+user.ScreenName+
": Hi! You've been blocked by @"+cfg.Settings.MyScreenName+
". Reason: "+cfg.Settings.ReasonsURL+"#"+ruleName, params)
if err2 != nil {
log.Fatalf("Failed to notify blocked user: %s", err2)
}
// Display tweet in terminal
fmt.Println(">> " + tweet2.Text)
// Restore API to main account auth settings
anaconda.SetConsumerKey(cfg.Auth.ConsumerKey)
anaconda.SetConsumerSecret(cfg.Auth.ConsumerSecret)
}
示例7: FetchTweet
func FetchTweet(id int64, api *anaconda.TwitterApi) anaconda.Tweet {
tweet, err := api.GetTweet(id, nil)
if err != nil {
panic(err)
}
return tweet
}
示例8: checkForTweets
func checkForTweets(api anaconda.TwitterApi) error {
searchResult, err := api.GetHomeTimeline()
if err != nil {
log.Print("error fetching timeline: %v", err)
return err
}
//Assume that we haven't tweeted at each other more than 10 times since the last check
//Knowing us, this is a very bad assumption.
log.Printf("We have %d results", len(searchResult))
//Iterate over the tweets in chronological order (the reverse order from what is returned)
for i := len(searchResult) - 1; i >= 0; i-- {
tweet := searchResult[i]
if TweetMentionsATarget(tweet) {
if err := retweetAndLog(api, tweet); err != nil {
log.Print("error when retweeting %v", err)
continue
}
log.Print(tweet.Text)
} else {
//log.Printf("Skipping tweet %v", tweet.Text)
}
}
return nil
}
示例9: twitterHandler
func twitterHandler(api *anaconda.TwitterApi) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
re := regexp.MustCompile("(http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\[email protected]?^=%&/~+#-])?")
query := r.URL.Query().Get("q")
v := url.Values{}
//v.Set("f", "news")
v.Set("lang", "en")
v.Set("count", "100")
result, err := api.GetSearch(query, v)
if err != nil {
handleWebErr(w, err)
return
}
var results []string
for _, tweet := range result.Statuses {
results = append(results, re.ReplaceAllLiteralString(tweet.Text, ""))
}
msg, err := json.Marshal(results)
if err != nil {
handleWebErr(w, err)
return
}
w.Header().Set("Content-Type", "application/json")
fmt.Fprint(w, string(msg))
}
}
示例10: GenerateFireworkFor
func GenerateFireworkFor(api *anaconda.TwitterApi, t *anaconda.Tweet) error {
checkFile := MakeGifFilename(t.User.ScreenName, t.Id)
if Exists(checkFile) {
fmt.Println("Already Exsists")
return nil
}
v := url.Values{}
v.Set("screen_name", t.User.ScreenName)
v.Set("count", "30")
search_result, err := api.GetUserTimeline(v)
if err != nil {
return err
}
gifFile, e := genTwitterGif(search_result, t.User.ScreenName, t.Id)
if e != nil {
return e
}
if *live {
return postImageTweet(api, gifFile, t)
} else {
fmt.Println("Not live: ", live, t.User.ScreenName, gifFile)
}
return nil
}
示例11: GetSearchStream
func (tc *TwitterController) GetSearchStream(api *anaconda.TwitterApi, query string) chan anaconda.Tweet {
c := make(chan anaconda.Tweet)
go func(chanNotify chan anaconda.Tweet) {
var since_id int64
for {
v := url.Values{}
v.Set("local", "ja")
v.Set("count", "20")
if since_id > 0 {
ssince_id := strconv.FormatInt(since_id, 10)
v.Set("since_id", ssince_id)
}
resp, err := api.GetSearch(query, v)
if err == nil {
for _, status := range resp.Statuses {
chanNotify <- status
if status.Id > since_id {
since_id = status.Id
}
}
} else {
log.Printf("An error occured while searching. err:%v", err)
}
time.Sleep(time.Second * 30)
}
}(c)
return c
}
示例12: ShowTimeline
// 指定したユーザのTweetを表示する。
func ShowTimeline(api *anaconda.TwitterApi, v url.Values, screenName string) {
v.Set("screen_name", screenName)
tweets, err := api.GetUserTimeline(v)
check(err)
for _, tweet := range tweets {
PrintTweet(tweet)
}
}
示例13: updateStatus
func updateStatus(subject string, api anaconda.TwitterApi) bool {
_, err := api.PostTweet(subject, nil)
if err != nil {
fmt.Println("Posting Tweet failed! Error : ", err)
os.Exit(1)
}
return true
}
示例14: updateTimeline
func updateTimeline(api *an.TwitterApi) []an.Tweet {
v := url.Values{}
home, err := api.GetHomeTimeline(v)
if err != nil {
fmt.Println("error: ", err)
}
return home
}
示例15: getLatestTweets
func getLatestTweets(client *anaconda.TwitterApi, screenName string, length int) (tweets []anaconda.Tweet, err error) {
query := url.Values{}
query.Set("screen_name", screenName)
query.Set("count", fmt.Sprintf("%v", length))
query.Set("trim_user", "true")
query.Set("exclude_replies", "true")
query.Set("include_rts", "true")
return client.GetUserTimeline(query)
}