How to run EXPLAIN ANALYZE and get results of the query?
If you do:

set auto_explain.log_min_duration TO 0;
set auto_explain.log_level TO notice ;
set auto_explain.log_analyze to on;


then the client will receive the execution analysis.  You just need to make it capture that message and distinguish them from other messages that might come along on the same channel.  If you need an example, 'psql' does capture and display these messages (but doesn't interpret them).