Пример #1
0
func TestTag(t *testing.T) {
	var tag = social.Tag("EXPO")
	_, err := tw.GetByTag(tag, nil, nil)
	if err != nil {
		t.Error(err)
	}
}
Пример #2
0
// ToPost converts a tweet into a Post structure
func (tw Twitter) ToPost(data interface{}) (post social.Post, err error) {
	// Fixed
	post.Source = "twitter"

	var tweet = data.(twittergo.Tweet)
	post.ID = tweet.IdStr()
	post.Text = tweet.Text()
	post.Date = tweet.CreatedAt()

	// Language
	post.Lang = tweet.Language()

	// Tags
	var tags = make(social.Tags, 0)
	if tweet["entities"] != nil {
		var entities = tweet["entities"].(map[string]interface{})
		if entities["hashtags"] != nil {
			var hashtags = entities["hashtags"].([]interface{})
			for _, item := range hashtags {
				var hashtag = item.(map[string]interface{})
				var tag = social.Tag(hashtag["text"].(string))
				tags = append(tags, tag)
			}
		}
	}
	post.Tags = tags

	// Author
	var user = tweet.User()
	post.Author = user.Name()
	post.AuthorID = user.IdStr()

	// Location
	var location *social.Location
	if tweet["coordinates"] != nil {
		var geoPoint = tweet["coordinates"].(map[string]interface{})
		var coordinates = geoPoint["coordinates"].([]interface{})
		var lon = coordinates[0].(float64)
		var lat = coordinates[1].(float64)
		location = social.NewLocation(lat, lon)
	}
	post.Location = location

	// Nil
	post.Nil = -1

	return post, nil
}
Пример #3
0
func main() {
	var tw *twitter.Twitter

	var credentials = &social.Credentials{
		Key:    "sCCiDYz9iNtm2KVw4jHAA",
		Secret: "M8oCAm1KNd04RlPrkmGRGjoWvYUcIqY8my8eS3txcjQ",
	}

	tw, _ = twitter.New(credentials)

	var tag = social.Tag("Maserati")

	var options = social.DefaultOptions()
	options.Count = 1000
	options.MaxPages = 0
	// options.Paginate = false

	posts, pages, err := tw.GetByTag(tag, options, nil)
	if err != nil {
		log.Error(err)
	}
	log.Infof("Got %d posts from %d page/s", len(posts), pages)
}