This depends on how you think about metaphor and metonymy. In the rhetorical tradition, you'd have to be very specific about how you label each trope. E.g. distinguishing metonymy from synechdoche. But I don't generally find this approach helpful.
If you're interested in the conceptual underpinnings of proverbs, you're better off with the conceptual metaphor theory which thinks of both metaphor and metonymy as two broad structuring principles of human cognition. Subsuming analogy, parable, simile, etc. under metaphor and synechdoche under metonymy.
The key distinction between metaphor and metonymy from the conceptual metaphor theory perspective is that between similarity and contiguity (or relatedness). I wrote a more detailed comparison on MetaphorHacker.net.
With this in mind, you can easily see that in the first proverb, the apple stands for fruit (member of a category standing for category) which stands for health (cause for outcome) in a chain of metonymies. Doctor stands for illness (profession for area of expertise). So you can see that the conceptual domain is primarily structured metonymically. However, you also need the relationship of similarity to understand the whole proverb as 'if you eat fruit you will not get ill' by projecting the configuration into a real world situation.
The second proverb, on the other hand, does not depend on metonymy for its conceptual structure. It asks you to project the situation of somebody who is asking without being able to offer anything in return onto your own situation. Therefore, you always need to find something in a given situation that makes one person the beggar and another person the giver and something the gift. So for instance, if you really need a job and somebody offers your a job you don't like but you can't avoid taking it, you might say that this proverb applies here. This is very typical of how metaphors work.