The second-quarter results showed the Facebook parent’s core ad business remains strong at a time when the company is investing billions of dollars into artificial intellilgence.