本文整理汇总了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
}