Sunan Ibn Majah, Book 12, Hadith 2388 (In-Book) ⓘ
It was narrated from Abu Sa'eed that the Prophet said: "When you come to a shepherd, call him three times. If he answers (all well and good), otherwise drink (milk from the flock) without taking advantage. And when you come to a garden call the owner of the garden three times. If he answers (all well and good), otherwise eat (from the produce of the garden) without taking advantage."
حَدَّثَنَا مُحَمَّدُ بْنُ يَحْيَى، حَدَّثَنَا يَزِيدُ بْنُ هَارُونَ، أَنْبَأَنَا الْجُرَيْرِيُّ، عَنْ أَبِي نَضْرَةَ، عَنْ أَبِي سَعِيدٍ، عَنِ النَّبِيِّ ـ صلى الله عليه وسلم ـ قَالَ " إِذَا أَتَيْتَ عَلَى رَاعٍ فَنَادِهِ ثَلاَثَ مِرَارٍ فَإِنْ أَجَابَكَ وَإِلاَّ فَاشْرَبْ فِي غَيْرِ أَنْ تُفْسِدَ وَإِذَا أَتَيْتَ عَلَى حَائِطِ بُسْتَانٍ فَنَادِ صَاحِبَ الْبُسْتَانِ ثَلاَثَ مَرَّاتٍ فَإِنْ أَجَابَكَ وَإِلاَّ فَكُلْ فِي أَنْ لاَ تُفْسِدَ " .
also referenced under: Hadith 2300 (Reference) & Volume 3, Book 12, Hadith 2300 (DarusSalam)