There is no magic number of AP classes a student should take but it’s important to bear in mind that if you intend on applying to the more selective universities, you should take the most challenging courses available to you, which include AP classes. Ivy Leagues and other selective universities look for students who have challenged themselves throughout high school and excelled.
Yale states the following on their admissions website, ‘Does your school offer AP courses? An International Baccalaureate program? Both? Neither? We know you did not design your school’s curriculum, and we only expect you to take advantage of such courses if your high school provides them’- https://admissions.yale.edu/advice-selecting-high-school-courses
Stanford’s view is the following, 'We expect you to challenge yourself throughout high school and to do very well. The most important credential that enables us to evaluate your academic record is the high school transcript. Remember, however, that our evaluation of your application goes beyond any numerical formula. There is no minimum GPA or test score; nor is there any specific number of AP or honors courses you must have on your transcript that will secure your admission to Stanford.'- https://admission.stanford.edu/apply/selection/index.html
Harvard College also expects students to take the most rigorous course available to students. 'Most of all, we look for students who make the most of their opportunities and the resources available to them, and who are likely to continue to do so throughout their lives … You should demonstrate your proficiency in the areas described below by taking SAT II Subject Tests, Advanced Placement tests, and International Baccalaureate tests.'- https://college.harvard.edu/admissions/preparing-college/choosing-courses
With this in mind, you should be looking to take courses that stretch you but also interest you, especially if they relate to a subject you wish to major in university. What students want to avoid is loading up on AP courses that have no relation to what they want to study at university and potentially bring down their GPA.