Marwan said to his gatekeeper, "Go, Rafi, to Ibn Abbas and say to him, 'If every one of us who rejoices in what he has done and loves to be praised for what he has not done is to be punished, then we shall all be punished.'"Ibn Abbas replied, "What have you to do with this verse? This verse was revealed only concerning the People of the Book."Then Ibn Abbas recited, "And when Allah took the covenant of those who were given the Scripture, that you make it clear to the people and do not conceal it" [Aal Imran 3:187], and he recited, "Do not think that those who rejoice in what they have done and love to be praised for what they have not done" [Aal Imran 3:188].Ibn Abbas explained, "The Prophet ﷺ asked them about something, and they concealed it from him and told him something else instead. They left having shown him that they had answered his question, and they sought his praise for that, and they rejoiced in what they had achieved by concealing from him what he had asked them about."
أن مروان قال: اذهب يا رافع- لبوابه- إلى ابن عباس فقل: لئن كان كل امرئ منا فرح بما أتى وأحب أن يحمد بما لم يفعل معذبا لنعذبن أجمعون. فقال ابن عباس: ما لكم ولهذه الآية، إنما أنزلت هذه الآية في أهل الكتاب. ثم تلا ابن عباس: {وإذ أخذ الله ميثاق الذين أوتوا الكتاب لتبيننه للناس ولا تكتمونه} هذه الآية، وتلا ابن عباس: {لا تحسبن الذين يفرحون بما أتوا ويحبون أن يحمدوا بما لم يفعلوا} وقال ابن عباس: سألهم النبي ﷺ عن شيء فكتموه إياه، وأخبروه بغيره، فخرجوا قد أروه أن قد أخبروه بما سألهم عنه، واستحمدوا بذلك إليه، وفرحوا بما أتوا من كتمانهم إياه ما سألهم عنه.
Bukhari narrated it in the tafsir (4568m), and Muslim in the description of the hypocrites (2778), both by way of Hajjaj bin Muhammad from Ibn Jurayj, who said, Ibn Abu Mulayka told me that Humayd bin Abdul-Rahman bin Awf informed him, and he related it. The wording given is Muslim's, while Bukhari did not state its wording with this chain of transmission, but instead referred back to the narration before it, which is similar in meaning.