本文整理匯總了Golang中github.com/ChimeraCoder/anaconda.TwitterApi.BlockUserId方法的典型用法代碼示例。如果您正苦於以下問題:Golang TwitterApi.BlockUserId方法的具體用法?Golang TwitterApi.BlockUserId怎麽用?Golang TwitterApi.BlockUserId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ChimeraCoder/anaconda.TwitterApi
的用法示例。
在下文中一共展示了TwitterApi.BlockUserId方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2: blockUser
func blockUser(user User, api *anaconda.TwitterApi) (twitterUser anaconda.User, err error) {
// userIDが0かuserIDの長さが10でないと気はscreenNameでブロックする
if user.id == 0 || len(user.screenName) != 10 {
// screen_name の時
if twitterUser, err = api.BlockUser(user.screenName, nil); err == nil {
return twitterUser, nil
}
} else {
// Id の時
if _, err := api.BlockUserId(user.id, nil); err == nil {
return twitterUser, nil
}
}
return
}