本文整理匯總了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
}
示例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))
}
}
示例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
}
示例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))
}
}
}
示例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
}