当前位置: 首页>>代码示例>>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;未经允许,请勿转载。