Example code for connecting to API Analytics Google

PHP file code, script for authorization and connection to Google Analytics. How to get an API token Google Analytics. How to renew the API token Google Analytics. An example of an access code to the API Analytics Google. Connection errors.