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


Golang TwitterApi.PostTweet方法代码示例

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


在下文中一共展示了TwitterApi.PostTweet方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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
}
开发者ID:jprobinson,项目名称:NYTPlusContextBot,代码行数:7,代码来源:twitter.go

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

示例3: 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
}
开发者ID:istanbul-coders,项目名称:monsterghost,代码行数:8,代码来源:tweet.go

示例4: Tweet

func Tweet(status string) (tweet anaconda.Tweet, err error) {
	var client *anaconda.TwitterApi
	if twitterClient != nil {
		client = twitterClient
	} else {
		client = TwitterClient()
	}
	return client.PostTweet(status, url.Values{})
}
开发者ID:RockinTechBomb,项目名称:fx-devtools-bot,代码行数:9,代码来源:tweet.go

示例5: PostTweets

func PostTweets(api *anaconda.TwitterApi, bts []BeetTweet, db *sql.DB) {
	for _, bt := range bts {
		//TODO: Psuedo random reminder messages. For fun, and not angering the twitter api.
		_, err := api.PostTweet(fmt.Sprintf("@%s The number is %d.", bt.Name, bt.Hours), nil)

		if err == nil {
			query := fmt.Sprintf("UPDATE tweet SET NOTIFIED = true WHERE ID = %d;", bt.Id)
			db.Query(query)
		}
	}
}
开发者ID:mrkplt,项目名称:you_ate_beets,代码行数:11,代码来源:beet_tweet.go

示例6: tweetCurrent

// Given config and observation, tweets latest update
func tweetCurrent(config Config, o string) {
	fmt.Println("Preparing to tweet observation...")
	var api *anaconda.TwitterApi
	api = anaconda.NewTwitterApi(config.Token, config.TokenSecret)
	anaconda.SetConsumerKey(config.ConsumerKey)
	anaconda.SetConsumerSecret(config.ConsumerSecret)
	tweet, err := api.PostTweet(o, nil)
	if err != nil {
		fmt.Println("update error:", err)
	} else {
		fmt.Println("Tweet posted:")
		fmt.Println(tweet.Text)
	}
}
开发者ID:carriercomm,项目名称:BuoyBot,代码行数:15,代码来源:buoybot.go

示例7: feedJBBS2Twitter

func feedJBBS2Twitter(board *jbbsreader.Board, api *anaconda.TwitterApi) error {
	done := make(chan struct{})
	defer close(done)
	respc, errc := board.FeedNewResponses(done)
	for resp := range respc {
		log.Printf("Fetched %#v\n", resp)
		tweet, err := api.PostTweet(resp.Content, nil)
		if err != nil {
			return err
		}
		log.Printf("Sent tweet %#v\n", tweet)
	}
	return <-errc
}
开发者ID:mogepiyo,项目名称:jbbs2twitter,代码行数:14,代码来源:jbbs2twitter.go

示例8: Respond

// Respond to an image somebody posted
func Respond(tweet anaconda.Tweet, classification string, twitter anaconda.TwitterApi) bool {
	msg := fmt.Sprintf(
		"%s https://twitter.com/%s/status/%s",
		message(classification),
		tweet.User.IdStr,
		tweet.IdStr,
	)

	reply, errRpl := twitter.PostTweet(msg, url.Values{})

	if errRpl != nil {
		log.Printf("Error responding: ", errRpl)
		return false
	}

	// else
	log.Printf("Tweeted; link: https://twitter.com/%s/status/%d\n", reply.User.ScreenName, reply.Id)
	return true
}
开发者ID:bjacobel,项目名称:goggles,代码行数:20,代码来源:postTweet.go

示例9: tweet

//ツイート関数。無駄に並列化している。140字以上の分割ツイートにも対応。
func tweet(api *anaconda.TwitterApi, waitGroup *sync.WaitGroup, begin string, end string, str string) {
	sLen := 140 - utf8.RuneCountInString(begin) - utf8.RuneCountInString(end)
	for str != "" {
		limit := int(math.Min(float64(sLen), float64(utf8.RuneCountInString(str))))
		waitGroup.Add(1)
		go func(api *anaconda.TwitterApi, waitGroup *sync.WaitGroup, begin, end, str string) {
			defer waitGroup.Done()
			tweetstr := begin + str + end
			if *r {
				tweetstr = reverse(tweetstr)
			}
			if *h {
				hash := sha256.Sum256([]byte(tweetstr))
				tweetstr = hex.EncodeToString(hash[:])
			}

			api.PostTweet(tweetstr, nil)
		}(api, waitGroup, begin, end, string([]rune(str)[:limit]))
		str = string([]rune(str)[limit:])
	}
}
开发者ID:Goryudyuma,项目名称:go-work,代码行数:22,代码来源:tw.go

示例10: PostTweet

func PostTweet(api *anaconda.TwitterApi, reader io.ReadCloser) error {
	buff := bytes.Buffer{}
	encoder := base64.NewEncoder(base64.StdEncoding, &buff)

	_, err := io.Copy(encoder, reader)
	if err != nil {
		return err
	}
	reader.Close()
	encoder.Close()

	media, err := api.UploadMedia(buff.String())
	if err != nil {
		return err
	}

	values := url.Values{}
	values.Set("media_ids", fmt.Sprintf("%d", media.MediaID))
	_, err = api.PostTweet("", values)
	if err != nil {
		fmt.Println(err)
	}
	return nil
}
开发者ID:ironmig,项目名称:AInspirationBot,代码行数:24,代码来源:main.go

示例11: gameGenerator

func gameGenerator(api *anaconda.TwitterApi) func(anaconda.Tweet) bool {
	var enemyHp int = 3 //HP is Hit Point
	var myHp int = 3
	var enemyTp int = 0 //Tp is Tame Point
	var myTp int = 0
	var turn int = 0
	var maouRoutine = [3][10]int{
		{0, 1, 0, 2, 0, 0, 0, 2, 0, 1}, //攻撃60%防御20%タメ20%
		{1, 1, 1, 0, 0, 2, 2, 1, 1, 1}, //攻撃20%防御60%タメ20%
		{0, 1, 1, 0, 2, 0, 1, 1, 1, 0}, //攻撃40%防御50%タメ10%
	}
	var commands = [4]string{"こうげき", "ぼうぎょ", "ため", "ひっさつ"}
	var lossRep = " あなたの負けです"
	var winRep = " あなたの勝ちです"

	//げーむるーちん
	return func(tweet anaconda.Tweet) bool {
		//fmt.Println("tw",tweet.Text)
		//fmt.Println("turn",)
		var act = -1

		for i := 0; i < len(commands); i++ {
			if strings.Contains(tweet.Text, commands[i]) {
				act = i
				break
			}
		}
		if act < 0 {
			return false
		}

		turn++
		turn %= len(maouRoutine)
		rand.Seed(time.Now().UnixNano())
		routine := rand.Intn(10)
		mact := maouRoutine[turn][routine]
		if enemyTp == 3 {
			mact = 3
		}

		sendmess := "@" + tweet.User.ScreenName + " "
		sendmess += "勇者は" + commands[act] + "をした\n"
		sendmess += "魔王は" + commands[mact] + "をした\n"

		//以下、初心者あともすふぇあ満載のif祭り
		//こうげき
		if mact == 0 && act != 1 {
			sendmess += "勇者はダメージを受けた\n"
			myHp--
		}
		if mact != 1 && act == 0 {
			sendmess += "魔王はダメージを受けた\n"
			enemyHp--
		}

		//ため
		if act == 2 {
			myTp++
			sendmess += "勇者タメ" + strconv.Itoa(myTp) + "\n"
		}
		if mact == 2 {
			enemyTp++
			sendmess += "魔王タメ" + strconv.Itoa(enemyTp) + "\n"
		}

		//ひっさつ
		if mact == 3 {
			sendmess += "勇者は必殺を受けた\n"
			if act == 1 {
				myHp++
			}
			myHp -= 3
			enemyTp = 0
		}
		if act == 3 {
			if myTp < 3 {
				sendmess += "勇者はためが足りなかった\n"
			} else {
				sendmess += "魔王は必殺を受けた\n"
				if mact == 1 {
					enemyHp++
				}
				enemyHp -= 3
			}
			myTp = 0
		}

		if enemyHp <= 0 {
			sendmess += winRep
		} else if myHp <= 0 {
			sendmess += lossRep
		}

		api.PostTweet(sendmess+"【"+tweet.IdStr+"】"+tag, nil)

		return enemyHp <= 0 || myHp <= 0
	}
}
开发者ID:KazushiSakashita,项目名称:MAOUVS,代码行数:98,代码来源:test.go

示例12: onTweet

func onTweet(api *anaconda.TwitterApi, tw anaconda.Tweet) {
	log.Printf("Tweet: %s", tw.Text)
	var err error
	if urlRegexp == nil {
		urlRegexp, err = regexp.Compile(kUrlRegexp)
		if err != nil {
			log.Fatal(err)
		}
	}
	text := tw.Text
	text = urlRegexp.ReplaceAllString(text, "")
	rs, err := mecab.Parse(text)
	if err != nil {
		log.Fatal(err)
	}
	strs := make([]string, len(rs))
	for i, r := range rs {
		strs[i] = r.Surface
	}
	log.Print(strs)
	alphas := 0
	for _, r := range rs {
		rlen := len([]rune(r.Surface))
		if count(kAlphabet, r.Surface) > (rlen / 2) {
			alphas++
		}
	}
	if alphas > (len(rs) / 2) {
		return
	}
	candidates := make([]string, 0)
	for _, r := range rs {
		if contains(kStopWords, r.Surface) {
			return
		}
		rlen := len([]rune(r.Surface))
		syms := count(kSymbols, r.Surface)
		if rlen <= 1 || (syms) > (rlen/2) {
			continue
		}
		f := r.Feature
		if !(r.Pos == "名詞" && !strings.Contains(f, "接尾") &&
			!strings.Contains(f, "代名詞") &&
			!strings.Contains(f, "接頭詞") &&
			!strings.Contains(f, "形容動詞語幹")) {
			continue
		}
		candidates = append(candidates, r.Surface)
	}
	if len(candidates) <= 0 {
		return
	}
	c := candidates[rand.Intn(len(candidates))]
	log.Printf("%s as a Service\n", c)
	t, err := api.PostTweet(c+" as a Service", nil)
	if err != nil {
		log.Println(err)
	}
	log.Println(t)
	os.Exit(0)

}
开发者ID:jf-nights,项目名称:Everything_as_a_Service,代码行数:62,代码来源:main.go

示例13: tweet

func (g *gweet) tweet(api *anaconda.TwitterApi,
	text string, files []string, lewd bool) (tweetUrl string, err error) {

	log.Printf(`Tweeting {"%s", %v, lewd=%v}.`+"\n", text, files, lewd)

	var ids string
	var data []byte
	for _, filePath := range files {
		log.Println("Uploading", filePath)
		// TODO: refuse files larger than 15mb for vids and 5mb for images
		data, err = ioutil.ReadFile(filePath)
		if err != nil {
			return
		}

		/*mime*/ meme := http.DetectContentType(data)

		log.Println(meme)

		if !strings.HasPrefix( /*mime*/ meme, "image") {
			var media anaconda.ChunkedMedia
			var videoMedia anaconda.VideoMedia

			// TODO: do not read entire file to memory

			media, err = api.UploadVideoInit(len(data), "video/mp4")
			if err != nil {
				return
			}

			chunkIndex := 0
			for i := 0; i < len(data); i += 5242879 {
				log.Println("Chunk", chunkIndex)
				err = api.UploadVideoAppend(media.MediaIDString, chunkIndex,
					base64.StdEncoding.EncodeToString(
						data[i:int(math.Min(5242879.0, float64(len(data))))],
					),
				)
				if err != nil {
					return
				}
				chunkIndex++
			}

			videoMedia, err = api.UploadVideoFinalize(media.MediaIDString)
			if err != nil {
				return
			}

			ids += videoMedia.MediaIDString
			ids += ","
		} else {
			var media anaconda.Media
			media, err = api.UploadMedia(
				base64.StdEncoding.EncodeToString(data))
			ids += media.MediaIDString
			ids += ","
		}
		if err != nil {
			return
		}
	}

	ids = ids[:len(ids)-1]
	log.Println("media_ids:", ids)
	v := url.Values{}
	v.Set("media_ids", ids)
	v.Set("possibly_sensitive", strconv.FormatBool(lewd))
	tweet, err := api.PostTweet(text, v)
	if err != nil {
		return
	}

	tweetUrl = fmt.Sprintf("https://twitter.com/%s/status/%s",
		tweet.User.ScreenName, tweet.IdStr)

	return
}
开发者ID:Francesco149,项目名称:gweet,代码行数:78,代码来源:main.go


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