gmail api客户端身份验证php

i'm using a guide on gmail site but i don't understand in witch way i can send back the autorization from google to my application :

if i use this code on a guide (https://developers.google.com/gmail/api/quickstart/php ) i need to put inside my application the authcode after i went on a google auth page:

    $authUrl = $client->createAuthUrl();
    header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL));
    $accessToken = $client->authenticate(AUTORIZATIONCODE);

and using this sistem the authcode work all time i want (i use this sistem 2 weeks ago and i don't need to relogin)

there is a method to put the auth inside the application with out copy the code using copy/paste? and save this code temporay ( 1 day ? 1 week?)

(i create OAuth 2.0 client ID Credentials on google develope is correct ?)

UPDATE!!!

if you need to create an autorizationcode using just a consent screen you need to this step:

1- create a Web application Credential

2- add in this credential the redirect page

3- and change this line inside page this :

$accessToken = $client->authenticate($_GET['code']);

(the expiration time is 3600 )