Can I say this: "To spank my shoulder when needed" or "to spank on my shoulder when I'm down in life"? Is there a way instead not using spank? Is there any other way to express the same feeling?
There is some confusion here between several idioms. First, never spank anyone on anything as spanking is a mild form of corporal punishment and I'm sure you don't mean that.
a pat on the back is giving someone praise
a pat on the shoulder is a consolatory gesture (I think this is the one you are thinking of)
a tap on the shoulder is either simply getting someone's attention, or calling someone up for promotion or some other more important duty
There isn't really a physical difference between a pat on the back or a pat on the shoulder, it's all about context, but in English we use two phrases to differentiate between the two intentions.
If the motion is light, I'd go for a "pat on the shoulder". For example, the kind of thing you'd give a friend to console them after their loss. If it's more percussive, I think I'd go for a "clap on the shoulder", such as you might give someone right before they head out onto the field for a game. As noted above, "spank" contains much different associations which I doubt are what you're aiming for.