本文整理匯總了Golang中github.com/ChimeraCoder/anaconda.TwitterApi.GetFriendsIds方法的典型用法代碼示例。如果您正苦於以下問題:Golang TwitterApi.GetFriendsIds方法的具體用法?Golang TwitterApi.GetFriendsIds怎麽用?Golang TwitterApi.GetFriendsIds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ChimeraCoder/anaconda.TwitterApi
的用法示例。
在下文中一共展示了TwitterApi.GetFriendsIds方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: fetchTwitterFriends
// 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
}
示例2: getFriendIDs
// 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)
}