I think Dire de la merde, Dire des conneries is more apropriate.
It doesn’t necessarily relate to someone.
Using “talk shit” Urban Dictionary definitions
1.) To say something insulting or rude about another person, either to their face or behind their back.
2.) To make a statement that is exaggerated or flat-out untrue
- Raconter des conneries
3.) To say something negative behind someone’s back that you wouldn’t say to their face.
Your sentence “He was talking shit about me but I had to hear it from someone else” might then be translated with:
Il racontait un tas de conneries sur moi mais il a fallu que je l’apprenne de quelqu’un d’autre.