Nouns take accusative case mainly when they are directly receiving some action (they are direct objects).
"Ich habe dich lieb." Yes, it's an idiom, but the accusative "dich" is consistent with the general concept of the accusative.
Dative is mainly for when something or someone receives an indirect action (is an indirect object).
"Wie geht's dir?" Also an idiom; nevertheless consistent with the dative concept. In English, a literal rendering might be "How's it going (for/with) you?" Modern English has no special morphology for accusative and dative, unlike German. English uses words like "to", "for", and "with" to represent the dative.
"Es steht mir, er hat mich geschlagen." It seems to me (dative), that he struck me (accusative).
"Ich möchte dich auf ein Bier einladen." I'd like to buy you (accusative) a beer.
"Ich kann ihm nicht glauben." I can't believe him (dative).
"Es gehört zu mir." It belongs to me (dative).
Most of the time it makes sense. There are a few situations, like "I can't believe him" above, in which English speakers don't necessarily think of believing as something dative. We probably conceive of it as more of an accusative flavor in English.
Even native speakers occasionally experience uncertainty about when to use accusative or dative. Most of the time, it's clear enough, but there is a trend in some dialects to conflate the two cases, at least when it comes to personal pronouns.