The entangled ergodic theorem in the almost periodic case