The problem is solved. The problem was that the tweet was sent at the same time the page was published and it seems the Twitter bot didn’t get the data it needed for generating a card.
I solved this by first sending a page request to the newly published page via the PHP function file_get_contents($page_url); and after that sending the tweet via the api.