Exemplo n.º 1
0
// Returns a slice with twitter ids of the given user's friends
func fetchTwitterFriends(screenName string, api *anaconda.TwitterApi) ([]string, error) {
	if api == nil {
		// Let's just pretend he has no friends, because we can't actually ask
		// Twitter about it
		return []string{}, nil
	}

	v := url.Values{}
	v.Set("count", "100")
	v.Set("cursor", "-1")
	v.Set("screen_name", screenName)

	friendsIds, err := api.GetFriendsIds(v)
	if err != nil {
		return nil, err
	}

	friends, err := api.GetUsersLookupByIds(friendsIds.Ids, url.Values{})
	if err != nil {
		return nil, err
	}

	var friendsNames []string
	for _, friend := range friends {
		friendsNames = append(friendsNames, friend.ScreenName)
	}

	return friendsNames, nil
}
Exemplo n.º 2
0
// Get friends' user IDs
func getFriendIDs(friendsCount string, api *anaconda.TwitterApi) map[int64]bool {
	params := url.Values{}
	params.Set("count", friendsCount)

	// Get the list of IDs from the API
	friendsIdsAll, err := api.GetFriendsIds(params)
	if err != nil {
		log.Fatalf("Failed to get friends data: %s", err)
	}
	friendsIdsTemp := friendsIdsAll.Ids

	// Create a map
	friendsIds := make(map[int64]bool)
	for _, friendId := range friendsIdsTemp {
		friendsIds[friendId] = true
	}

	return (friendsIds)
}