本文整理汇总了Golang中github.com/ChimeraCoder/anaconda.SetConsumerSecret函数的典型用法代码示例。如果您正苦于以下问题:Golang SetConsumerSecret函数的具体用法?Golang SetConsumerSecret怎么用?Golang SetConsumerSecret使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetConsumerSecret函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: main
func main() {
// устанавливаем соединение
port, err := sio.Open("/dev/ttyACM0", syscall.B9600)
if err != nil {
log.Fatal(err)
}
time.Sleep(2 * time.Second)
anaconda.SetConsumerKey(consumerKey)
anaconda.SetConsumerSecret(consumerSecret)
api := anaconda.NewTwitterApi(key, secretKey)
var twitt string
var searchResult []anaconda.Tweet
for {
searchResult, _ = api.GetSearch("#golang", nil)
twitt = " -- " + searchResult[0].Text
fmt.Println(twitt)
// отправляем данные
_, err = port.Write([]byte(twitt))
if err != nil {
log.Fatal(err)
}
time.Sleep(120 * time.Second)
}
}
示例3: getTweets
//getTweets gets all tweets from twitter with the speified keyword
func (tr TweetRetriever) getTweets(query string,
cutoff time.Time,
wg *sync.WaitGroup) {
defer wg.Done()
log.Infof(tr.context, "Downloading Tweets.")
anaconda.SetConsumerKey(consumerKey)
anaconda.SetConsumerSecret(consumerSecretKey)
api := anaconda.NewTwitterApi(accessToken, accessTokenSecret)
api.HttpClient.Transport = &urlfetch.Transport{Context: tr.context}
result, err := api.GetSearch(query, nil)
if err != nil {
log.Errorf(tr.context, "Harvester- getTweets: %v", err.Error())
return
}
cont := true
for cont {
cont = tr.addIfNewerThan(cutoff, result)
cont = false
if cont {
result, err = result.GetNext(api)
//log.Infof(c, "Getting more tweets!")
if err != nil {
log.Errorf(tr.context, "Harvester- getTweets: %v", err.Error())
}
}
}
close(tr.out)
}
示例4: main
func main() {
var apiConf ApiConf
{
// コマンドラインからフラグ付きで渡す
apiConfPath := flag.String("conf", "config.json", "API Config File")
flag.Parse()
data, err_file := ioutil.ReadFile(*apiConfPath)
check(err_file)
err_json := json.Unmarshal(data, &apiConf)
check(err_json)
}
anaconda.SetConsumerKey(apiConf.ConsumerKey)
anaconda.SetConsumerSecret(apiConf.ConsumerSecret)
api := anaconda.NewTwitterApi(apiConf.AccessToken, apiConf.AccessTokenSecret)
twitterStream := api.PublicStreamSample(nil)
for {
x := <-twitterStream.C
switch tweet := x.(type) {
case anaconda.Tweet:
fmt.Println(tweet.Text)
fmt.Println("-------")
case anaconda.StatusDeletionNotice:
// pass
default:
fmt.Printf("unknown type(%T) : %v \n", x, x)
}
}
}
示例5: main
func main() {
log.SetFlags(0)
// Load ET time zone
TZ_ET, _ = time.LoadLocation("America/New_York")
// Init the Twitter API
anaconda.SetConsumerKey(CONSUMER_KEY)
anaconda.SetConsumerSecret(CONSUMER_SECRET)
api := anaconda.NewTwitterApi(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
// Fetch it once
if err := fetchStats(api); err != nil {
log.Fatal(err)
}
// Start the web interface
go startWeb()
// Keep updating the stats every minute
for {
time.Sleep(time.Minute)
fetchStats(api)
}
}
示例6: sendTweet
func sendTweet(c context.Context, spreadsheetsID string, sheetID string, title string, path string, tags []string) error {
sheet, error := gapps.GetSpreadsheet(c, spreadsheetsID, sheetID)
if error != nil {
return error
}
log.Infof(c, title)
consumerKey := sheet.Table.Rows[1].C[0].V
consumerSecret := sheet.Table.Rows[1].C[1].V
accessToken := sheet.Table.Rows[1].C[2].V
accessTokenSecret := sheet.Table.Rows[1].C[3].V
tagString := ""
for _, tag := range tags {
tagString += " #" + tag
}
anaconda.SetConsumerKey(consumerKey)
anaconda.SetConsumerSecret(consumerSecret)
api := anaconda.NewTwitterApi(accessToken, accessTokenSecret)
api.HttpClient.Transport = &urlfetch.Transport{Context: c}
_, error = api.PostTweet(title+" "+path+tagString, nil)
if error != nil {
log.Infof(c, error.Error())
}
return nil
}
示例7: Save
func (self *Readtweets) Save(database, collection, words, limit string) bool {
session, err := mgo.Dial("localhost")
if err != nil {
panic(err)
}
defer session.Close()
session.SetMode(mgo.Monotonic, true)
tweets_collection := session.DB(database).C(collection)
anaconda.SetConsumerKey(self.consumerkey)
anaconda.SetConsumerSecret(self.consumersecret)
api := anaconda.NewTwitterApi(self.accesstoken, self.accessecret)
config := url.Values{}
config.Set("count", limit)
search, _ := api.GetSearch(words, config)
for _, tweet := range search {
reg := regexp.MustCompile("<a[^>]*>(.*?)</a>")
source := reg.FindAllStringSubmatch(tweet.Source, 1)
real_source := source[0][1]
media_list := []string{}
hashtag_list := []string{}
for _, media := range tweet.Entities.Media {
media_list = append(media_list, media.Media_url_https)
}
for _, hashtag := range tweet.Entities.Hashtags {
hashtag_list = append(hashtag_list, hashtag.Text)
}
t := &Tweet{
tweet.Id,
tweet.User.ScreenName,
tweet.User.ProfileImageUrlHttps,
tweet.User.FollowersCount,
tweet.User.Lang,
tweet.User.Location,
tweet.InReplyToScreenName,
real_source,
media_list,
hashtag_list,
tweet.Text,
tweet.CreatedAt,
}
tweets_collection.Insert(t)
}
return true
}
示例8: getFriendsAsUsers
//getFriendsAsUsers returns twitter friends as a slice of users sorted by User ID
func getFriendsAsUsers() []User {
anaconda.SetConsumerKey(conf.TwitterConsumerKey)
anaconda.SetConsumerSecret(conf.TwitterConsumerSecret)
api := anaconda.NewTwitterApi(conf.TwitterAccessToken, conf.TwitterAccessTokenSecret)
result := make(chan anaconda.UserCursor, 1000000) //YOLO
logger.Println("getting friends")
v := url.Values{}
v.Set("screen_name", conf.TwitterScreenName)
getFriends(api, result, v)
logger.Println("got em")
users := []User{}
for uc := range result {
for _, u := range uc.Users {
users = append(users, User{u.Id, u.Name, u.ScreenName, u.Description, u.Location})
}
}
sort.Sort(ById(users))
return users
}
示例9: main
func main() {
var err error
c, err = redis.Dial("tcp", REDIS_ADDRESS)
if err != nil {
panic(err)
}
defer c.Close()
log.Print("Successfully dialed Redis database")
auth_result, err := c.Do("AUTH", REDIS_PASSWORD)
if err != nil {
panic(err)
}
if auth_result == "OK" {
log.Print("Successfully authenticated Redis database")
}
log.Print("Successfully created Redis database connection")
anaconda.SetConsumerKey(TWITTER_CONSUMER_KEY)
anaconda.SetConsumerSecret(TWITTER_CONSUMER_SECRET)
api := anaconda.NewTwitterApi(TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET)
for {
go checkForTweets(api)
log.Printf("Sleeping for %d seconds", SLEEP_INTERVAL)
time.Sleep(SLEEP_INTERVAL * time.Second)
}
}
示例10: main
func main() {
consumerKey := os.Getenv("TWITTER_CONSUMER_KEY")
consumerSecret := os.Getenv("TWITTER_CONSUMER_SECRET")
accessToken := os.Getenv("TWITTER_ACCESS_TOKEN")
accessTokenSecret := os.Getenv("TWITTER_ACCESS_TOKEN_SECRET")
anaconda.SetConsumerKey(consumerKey)
anaconda.SetConsumerSecret(consumerSecret)
api := anaconda.NewTwitterApi(accessToken, accessTokenSecret)
user, err := api.GetSelf(nil)
if err != nil {
panic(err)
}
fmt.Printf("Logged in as @%s\n", user.ScreenName)
go doNotify("Twitter", "Logged in as @"+user.ScreenName, user.ProfileImageURL)
stream := api.UserStream(nil)
for {
select {
case data := <-stream.C:
if tweet, ok := data.(anaconda.Tweet); ok {
fmt.Printf("@%s: %s\n", tweet.User.ScreenName, tweet.Text)
go doNotify("@"+tweet.User.ScreenName, tweet.Text, tweet.User.ProfileImageURL)
}
}
}
fmt.Println("exiting")
}
示例11: NewStream
func NewStream(name string) (*Stream, error) {
anaconda.SetConsumerKey(consumer_key)
anaconda.SetConsumerSecret(consumer_secret)
api := anaconda.NewTwitterApi(access_token, access_token_secret)
api.SetLogger(anaconda.BasicLogger)
api.ReturnRateLimitError(true)
api.Log.Debugf("Fetching user %s...", name)
u, err := api.GetUsersShow(name, nil)
if err != nil {
return nil, errwrap.Wrapf(fmt.Sprintf("Failed to getUserShow() for %s: {{err}}", name), err)
}
api.Log.Debugf("Found user with id %d", u.Id)
vals := url.Values{}
vals.Set("follow", strconv.FormatInt(u.Id, 10))
return &Stream{
api: api,
fstream: api.PublicStreamFilter(vals),
user: u,
events: make(chan Event),
vulnerable: map[int64]*Vulnerable{},
}, nil
}
示例12: SendTweetResponse
func (t *TwitterUtil) SendTweetResponse(e *irc.Event, q string, tid string) {
anaconda.SetConsumerKey(opt.TwitterAppKey)
anaconda.SetConsumerSecret(opt.TwitterAppSecret)
api := anaconda.NewTwitterApi(opt.TwitterAuthKey, opt.TwitterAuthSecret)
vals := url.Values{}
pl := t.GetLoc(api)
if pl.err == nil {
vals.Add("lat", pl.lat)
vals.Add("long", pl.long)
vals.Add("place_id", pl.result.Result.Places[0].ID)
}
vals.Add("in_reply_to_status_id", tid)
tm, twe := t.GetNewTweetMedia(q)
if tm.MediaID != 0 {
vals.Add("media_ids", tm.MediaIDString)
}
tw, ter := api.PostTweet(twe, vals)
if ter == nil {
e.Connection.Privmsgf(e.Arguments[0], "[%s] Tweet sent [ https://twitter.com/%s/status/%s ]", e.Nick, tw.User.ScreenName, tw.IdStr)
} else {
e.Connection.Privmsgf(e.Arguments[0], "[%s] Tweet send failed: %s", e.Nick, ter)
}
api.Close()
}
示例13: SetLocation
func (t *TwitterUtil) SetLocation(e *irc.Event, txt string) {
if txt == "" {
t.Location = TweetLocation{}
t.LocationMode = 0
e.Connection.Privmsgf(e.Arguments[0], "[%s] Tweet location set to: random", e.Nick)
} else {
t.LocationMode = 1
anaconda.SetConsumerKey(opt.TwitterAppKey)
anaconda.SetConsumerSecret(opt.TwitterAppSecret)
api := anaconda.NewTwitterApi(opt.TwitterAuthKey, opt.TwitterAuthSecret)
vals := url.Values{}
vals.Add("query", url.QueryEscape(txt))
pl, ple := api.GeoSearch(vals)
if ple == nil && len(pl.Result.Places) > 0 && len(pl.Result.Places[0].Centroid) == 2 {
t.Location.result = pl
t.Location.err = nil
t.Location.lat = fmt.Sprintf("%.4f", pl.Result.Places[0].Centroid[1])
t.Location.long = fmt.Sprintf("%.4f", pl.Result.Places[0].Centroid[0])
e.Connection.Privmsgf(e.Arguments[0], "[%s] Tweet location set to: %s (https://www.google.com/maps?q=%s,%s)", e.Nick, pl.Result.Places[0].FullName, t.Location.lat, t.Location.long)
} else {
e.Connection.Privmsgf(e.Arguments[0], "[%s] Tweet location error: %s", e.Nick, ple)
}
api.Close()
}
}
示例14: GetNewTweetMedia
func (t *TwitterUtil) GetNewTweetMedia(txt string) (anaconda.Media, string) {
rx, _ := regexp.Compile("(http|https):\\/\\/([\\w.\\-\\/\\%#]+)")
rxm := rx.FindAllStringSubmatch(txt, -1)
if len(rxm) > 0 {
for i := 0; i < len(rxm); i++ {
rxm_i := rxm[i]
ml := rxm_i[0]
ht := new(HttpUtils)
mt := ht.GetContentType(ml)
if strings.Index(mt, "image") >= 0 {
anaconda.SetConsumerKey(opt.TwitterAppKey)
anaconda.SetConsumerSecret(opt.TwitterAppSecret)
api := anaconda.NewTwitterApi(opt.TwitterAuthKey, opt.TwitterAuthSecret)
bimg := ht.GetRemoteImageBase64(ml)
med, mer := api.UploadMedia(bimg)
api.Close()
if mer == nil {
return med, strings.Replace(txt, ml, "", -1)
} else {
fmt.Println(mer)
}
}
}
}
return anaconda.Media{}, txt
}
示例15: GetAuth
func GetAuth() (*anaconda.TwitterApi, error) {
file, err := os.Open("auth.json")
if err != nil {
return nil, err
}
decoder := json.NewDecoder(file)
info := AuthInfo{}
err = decoder.Decode(&info)
if err != nil {
return nil, err
}
anaconda.SetConsumerKey(info.ConsumerKey)
anaconda.SetConsumerSecret(info.ConsumerSecret)
api := anaconda.NewTwitterApi(info.Token, info.Secret)
ok, err := api.VerifyCredentials()
if err != nil {
return nil, err
}
if !ok {
return nil, errors.New("Invalid Credentials")
}
return api, nil
}