當前位置: 首頁>>代碼示例>>Golang>>正文


Golang TwitterApi.GetSearch方法代碼示例

本文整理匯總了Golang中github.com/ChimeraCoder/anaconda.TwitterApi.GetSearch方法的典型用法代碼示例。如果您正苦於以下問題:Golang TwitterApi.GetSearch方法的具體用法?Golang TwitterApi.GetSearch怎麽用?Golang TwitterApi.GetSearch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/ChimeraCoder/anaconda.TwitterApi的用法示例。


在下文中一共展示了TwitterApi.GetSearch方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetSearchStream

func (tc *TwitterController) GetSearchStream(api *anaconda.TwitterApi, query string) chan anaconda.Tweet {
	c := make(chan anaconda.Tweet)
	go func(chanNotify chan anaconda.Tweet) {
		var since_id int64
		for {
			v := url.Values{}
			v.Set("local", "ja")
			v.Set("count", "20")
			if since_id > 0 {
				ssince_id := strconv.FormatInt(since_id, 10)
				v.Set("since_id", ssince_id)
			}
			resp, err := api.GetSearch(query, v)
			if err == nil {
				for _, status := range resp.Statuses {
					chanNotify <- status
					if status.Id > since_id {
						since_id = status.Id
					}
				}
			} else {
				log.Printf("An error occured while searching. err:%v", err)
			}
			time.Sleep(time.Second * 30)
		}
	}(c)
	return c
}
開發者ID:harurock,項目名稱:moja,代碼行數:28,代碼來源:twitter.go

示例2: twitterHandler

func twitterHandler(api *anaconda.TwitterApi) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {

		re := regexp.MustCompile("(http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\[email protected]?^=%&/~+#-])?")

		query := r.URL.Query().Get("q")

		v := url.Values{}
		//v.Set("f", "news")
		v.Set("lang", "en")
		v.Set("count", "100")

		result, err := api.GetSearch(query, v)
		if err != nil {
			handleWebErr(w, err)
			return
		}

		var results []string

		for _, tweet := range result.Statuses {
			results = append(results, re.ReplaceAllLiteralString(tweet.Text, ""))
		}

		msg, err := json.Marshal(results)
		if err != nil {
			handleWebErr(w, err)
			return
		}

		w.Header().Set("Content-Type", "application/json")
		fmt.Fprint(w, string(msg))

	}
}
開發者ID:ohyeslk,項目名稱:DisasterResponse,代碼行數:35,代碼來源:twitter.go

示例3: twitterSearch

func twitterSearch(twitter *anaconda.TwitterApi, query string) ([]anaconda.Tweet, error) {

	v := url.Values{}
	//v.Set("f", "news")
	v.Set("lang", "en")
	v.Set("count", "100")

	result, err := twitter.GetSearch(query, v)
	if err != nil {
		return result.Statuses, err
	}
	return result.Statuses, nil
}
開發者ID:ohyeslk,項目名稱:DisasterResponse,代碼行數:13,代碼來源:twitter.go

示例4: doSearch

func doSearch(api *anaconda.TwitterApi, topic string) {
	// Test that the GetSearch function actually works and returns non-empty results
	search_result, err := api.GetSearch(topic, nil)
	if err != nil {
		ui.Error(fmt.Sprintf("GetSearch yielded error %v", err))
		panic(err)
	}

	// Unless something is seriously wrong, there should be at least two tweets
	if len(search_result.Statuses) < 2 {
		ui.Error(fmt.Sprintf("Expected 2 or more tweets, and found %d", len(search_result.Statuses)))
	}

	// Check that at least one tweet is non-empty
	for i, tweet := range search_result.Statuses {
		if tweet.Text != "" {
			ui.Info(fmt.Sprintf("[%d] %s", i, tweet.Text))
		}
	}
}
開發者ID:choueric,項目名稱:gogobird,代碼行數:20,代碼來源:gogobird.go

示例5: loadRecentTweets

func loadRecentTweets(api *anaconda.TwitterApi, conf *Config) error {
	val := url.Values{
		"count":            []string{"100"},
		"include_entities": []string{"true"},
	}
	for _, tsi := range conf.StreamInfo {
		tweets, err := api.GetSearch(tsi.GetTweetFilter(), val)
		if err != nil {
			return err
		}

		for _, t := range tweets.Statuses {
			tweet, err := convertTweet(t)
			if err != nil {
				// log here
				continue
			}
			tsi.Add(&tweet)
		}
	}

	return nil
}
開發者ID:kerwindena,項目名稱:koma-bot,代碼行數:23,代碼來源:twitter.go


注:本文中的github.com/ChimeraCoder/anaconda.TwitterApi.GetSearch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。