当前位置: 首页>>代码示例>>Golang>>正文


Golang anaconda.SetConsumerKey函数代码示例

本文整理汇总了Golang中github.com/ChimeraCoder/anaconda.SetConsumerKey函数的典型用法代码示例。如果您正苦于以下问题:Golang SetConsumerKey函数的具体用法?Golang SetConsumerKey怎么用?Golang SetConsumerKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SetConsumerKey函数的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)
}
开发者ID:denny,项目名称:MentionsManager,代码行数:32,代码来源:manager.go

示例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)
	}
}
开发者ID:4gophers,项目名称:goardiuno,代码行数:30,代码来源:main.go

示例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)
}
开发者ID:AndyNortrup,项目名称:TweetHarvest,代码行数:36,代码来源:tweet-retreiver.go

示例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)
		}
	}
}
开发者ID:YuheiNakasaka,项目名称:shakyo,代码行数:30,代码来源:twitter-streaming.go

示例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)
	}
}
开发者ID:rapidloop,项目名称:followtheleader,代码行数:25,代码来源:main.go

示例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
}
开发者ID:pgu,项目名称:onGolang,代码行数:26,代码来源:xblog.go

示例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
}
开发者ID:josueggh,项目名称:twoccer,代码行数:60,代码来源:readtweets.go

示例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
}
开发者ID:marcesher,项目名称:twitter_friend_changes,代码行数:26,代码来源:main.go

示例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)
	}

}
开发者ID:ChimeraCoder,项目名称:otterandjen,代码行数:34,代码来源:server.go

示例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")
}
开发者ID:maerlyn,项目名称:go-twitter-libnotify,代码行数:33,代码来源:main.go

示例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
}
开发者ID:pombredanne,项目名称:libsecurity,代码行数:26,代码来源:stream.go

示例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()
}
开发者ID:v0l,项目名称:gobot,代码行数:29,代码来源:TwitterUtil.go

示例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()
	}
}
开发者ID:v0l,项目名称:gobot,代码行数:30,代码来源:TwitterUtil.go

示例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
}
开发者ID:v0l,项目名称:gobot,代码行数:29,代码来源:TwitterUtil.go

示例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
}
开发者ID:ironmig,项目名称:AInspirationBot,代码行数:25,代码来源:main.go


注:本文中的github.com/ChimeraCoder/anaconda.SetConsumerKey函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。