// CallGetFriends calls the steam web API to retrieve a list of
// friends (steam IDs) for a given user.
// 		friendIDs, err := CallGetFriends(steamID)
CallGetFriends calls the steam web API to retrieve a list of
friends (steam IDs) for a given user.
friendIDs, err := CallGetFriends(steamID)
// CallGetFriends calls the steam web API to retrieve a list of // friends ( steam IDs ) for a given user . // friendIDs err : = CallGetFriends ( steamID )
func (control Cntr) CallGetFriends(steamID string) ([]string, error) {
	friendsListObj := common.UserDetails{}
	apiKey := apikeymanager.GetSteamAPIKey()
	maxRetryCount := 3
	successfulRequest := false
	targetURL := fmt.Sprintf("http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=%s&steamid=%s",
		apiKey, steamID)
	res, err := MakeNetworkGETRequest(targetURL)
	isError := IsErrorResponse(string(res))
	invalidKeyResponse := IsInvalidKeyResponse(string(res))
	if err != nil || isError || invalidKeyResponse {
		configuration.Logger.Warn(fmt.Sprintf("error from first call to GetFriendsList (%s), retrying now", targetURL),
			zap.String("errorMsg", fmt.Sprint(err)),
			zap.String("response", string(res)),
			zap.Bool("isError", isError),
			zap.Bool("invalidKeyResponse", invalidKeyResponse))
		for i := 0; i < maxRetryCount; i++ {
			noErrors := true
			apiKey = apikeymanager.GetSteamAPIKey()
			targetURL := fmt.Sprintf("http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=%s&steamid=%s",
				apiKey, steamID)
			res, err = MakeNetworkGETRequest(targetURL)
			if invalidKeyResponse := IsInvalidKeyResponse(string(res)); invalidKeyResponse {
				noErrors = false
				configuration.Logger.Warn(fmt.Sprintf("invalid key caused invalid key response on retry %d", i),
					zap.String("apiKey", apiKey),
					zap.String("targetURL", targetURL),
					zap.String("response", string(res)))
			}
			if isError := IsErrorResponse(string(res)); isError {
				noErrors = false
				configuration.Logger.Warn(fmt.Sprintf("Steam API returned Internal Server Error response on retry %d, sleeping for 3000ms", i),
					zap.String("apiKey", apiKey),
					zap.String("targetURL", targetURL),
					zap.String("response", string(res)))
				time.Sleep(3000 * time.Millisecond)
			}
			if err == nil && noErrors {
				configuration.Logger.Sugar().Infof("success on the %d request to GetFriendsList (%s)", i, targetURL)
				successfulRequest = true
				break
			}
			logMsg := fmt.Sprintf("failed to call get friends (%s) %d times", targetURL, i)
			configuration.Logger.Info(logMsg,
				zap.String("errorMsg", fmt.Sprint(err)),
				zap.String("response", string(res)),
				zap.Bool("isError", isError),
				zap.Bool("invalidKeyResponse", invalidKeyResponse))
		}
	} else {
		successfulRequest = true
	}
	if !successfulRequest {
		newErr := fmt.Errorf("failed %d retries to GetFriendList: %+v Most recent response: %+v", maxRetryCount, err, string(res))
		return []string{}, commonUtil.MakeErr(newErr)
	}
	err = json.Unmarshal(res, &friendsListObj)
	if err != nil {
		return []string{}, util.MakeErr(err, fmt.Sprintf("error unmarshaling friendsListObj object: %+v, got: %+v", friendsListObj, string(res)))
	}
	friendIDs := []string{}
	for _, friend := range friendsListObj.Friends.Friends {
		friendIDs = append(friendIDs, friend.Steamid)
	}
	return friendIDs, nil
}
func ( control Cntr ) CallGetFriends ( steamID string ) ( [ ] string , error ) { friendsListObj := common . UserDetails { } apiKey := apikeymanager . GetSteamAPIKey ( ) maxRetryCount := 3 successfulRequest := false targetURL := fmt . Sprintf ( " " , apiKey , steamID ) res , err := MakeNetworkGETRequest ( targetURL ) isError := IsErrorResponse ( string ( res ) ) invalidKeyResponse := IsInvalidKeyResponse ( string ( res ) ) if err != nil || isError || invalidKeyResponse { configuration . Logger . Warn ( fmt . Sprintf ( " " , targetURL ) , zap . String ( " " , fmt . Sprint ( err ) ) , zap . String ( " " , string ( res ) ) , zap . Bool ( " " , isError ) , zap . Bool ( " " , invalidKeyResponse ) ) for i := 0 ; i < maxRetryCount ; i ++ { noErrors := true apiKey = apikeymanager . GetSteamAPIKey ( ) targetURL := fmt . Sprintf ( " " , apiKey , steamID ) res , err = MakeNetworkGETRequest ( targetURL ) if invalidKeyResponse := IsInvalidKeyResponse ( string ( res ) ) ; invalidKeyResponse { noErrors = false configuration . Logger . Warn ( fmt . Sprintf ( " " , i ) , zap . String ( " " , apiKey ) , zap . String ( " " , targetURL ) , zap . String ( " " , string ( res ) ) ) } if isError := IsErrorResponse ( string ( res ) ) ; isError { noErrors = false configuration . Logger . Warn ( fmt . Sprintf ( " " , i ) , zap . String ( " " , apiKey ) , zap . String ( " " , targetURL ) , zap . String ( " " , string ( res ) ) ) time . Sleep ( 3000 * time . Millisecond ) } if err == nil && noErrors { configuration . Logger . Sugar ( ) . Infof ( " " , i , targetURL ) successfulRequest = true break } logMsg := fmt . Sprintf ( " " , targetURL , i ) configuration . Logger . Info ( logMsg , zap . String ( " " , fmt . Sprint ( err ) ) , zap . String ( " " , string ( res ) ) , zap . Bool ( " " , isError ) , zap . Bool ( " " , invalidKeyResponse ) ) } } else { successfulRequest = true } if ! successfulRequest { newErr := fmt . Errorf ( " " , maxRetryCount , err , string ( res ) ) return [ ] string { } , commonUtil . MakeErr ( newErr ) } err = json . Unmarshal ( res , & friendsListObj ) if err != nil { return [ ] string { } , util . MakeErr ( err , fmt . Sprintf ( " " , friendsListObj , string ( res ) ) ) } friendIDs := [ ] string { } for _ , friend := range friendsListObj . Friends . Friends { friendIDs = append ( friendIDs , friend . Steamid ) } return friendIDs , nil }
CallGetFriends calls the steam web API to retrieve a list of
friends (steam IDs) for a given user.
CallGetFriends calls the steam web API to retrieve a list of friends ( steam IDs ) for a given user .
// A fresh key must be used // No sleep is needed since KEY_USAGE_TIMER limits the distribution of steam keys