It is narrated from an Ansari Companion (may Allah be pleased with him): "The Messenger of Allah (peace and blessings be upon him) forbade facing the qiblah while defecating or urinating."
Imam Ahmad bin Hanbal and Imam Abu Bakr bin Abi Shaybah also narrated it; both of them, through the route of Isma'il from Ayyub from Nafi' (may Allah have mercy on him), from a man of the Ansar, from his father (a Companion, may Allah be pleased with him), that the Messenger of Allah (peace and blessings be upon him) (and then he narrated the complete hadith).
This chain is da'if (weak), because the Successor in it is majhul (unknown).