Insufficient Permission Gmail API
<p>I've read all topicks about this error, but still i have no idea what's wrong...
So, i just need to get list of user emails. </p>

<p>In API Console i've created a project and credentials. Also i have api key...</p>

<p>In Dashboard i have Gmail API enabled: <a href="http://joxi.ru/1A5bJvMhKo58Br" rel="nofollow noreferrer">http://joxi.ru/1A5bJvMhKo58Br</a></p>

<p>In my app after accepting permission i've got this error:</p>

<blockquote>
  <p>Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ "error": { "errors": [ { "domain": "global", "reason": "insufficientPermissions", "message": "Insufficient Permission" } ], "code": 403, "message": "Insufficient Permission" } } ' in /home/itindu04/it-industry.com.ua/tlso/api/src/Google/Http/REST.php:118 Stack trace: #0 /home/itindu04/it-industry.com.ua/tlso/api/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 [internal function]: Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 /home/itindu04/it-industry.com.ua/tlso/api/src/Google/Task/Runner.php(181): call_user_func_array(Array, Array) #3 /home/itindu04/it-industry.com.ua/tlso/api/src/Google/Http/REST.php(58): Google_Task_Runner->run() #4 /home/itindu04/it-industry.com.ua/tlso/api/src/Google/Client.php(781): Google_Http_REST::execute(Object(GuzzleH in /home/itindu04/it-industry.com.ua/tlso/api/src/Google/Http/REST.php on line 118</p>
</blockquote>

<p>Here is the code for get user's msgs:</p>

<pre><code>    require_once __DIR__ . '/api/vendor/autoload.php';
session_start();
$clientId = 'Client ID FROM API CONSOLE';
$clientSecret = 'CLIENT SECRET FROM API CONSOLE';
$redirectUri = 'http://' . $_SERVER['HTTP_HOST'] .'/index.php';

$client = new Google_Client();
$client-&gt;setClientId($clientId);
$client-&gt;setClientSecret($clientSecret);
$client-&gt;setRedirectUri($redirectUri);
$client-&gt;setDeveloperKey('DEV KEY FROM API CONSOLE');
//$client-&gt;addScope('https://mail.google.com/');
//$client-&gt;setAuthConfig('client_secret.json');
$client-&gt;setScopes(array(
    'https://mail.google.com/',
    'https://www.googleapis.com/auth/gmail.compose'
));
$service = new Google_Service_Gmail($client);
if (isset($_REQUEST['logout'])) {
    unset($_SESSION['access_token']);
}

if (isset($_GET['code'])) {
    $client-&gt;authenticate($_GET['code']);
    $_SESSION['access_token'] = $client-&gt;getAccessToken();
    $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    header('Location: ' . filter_var($url, FILTER_VALIDATE_URL));
}

if (isset($_SESSION['access_token'])) {
    $client-&gt;setAccessToken($_SESSION['access_token']);
    $drive_service = new Google_Service_Drive($client);
    $files_list = $drive_service-&gt;files-&gt;listFiles(array())-&gt;getItems();
    echo json_encode($files_list);
} else {
    $loginUrl = $client-&gt;createAuthUrl();
    echo 'Click &lt;a href="' . $loginUrl . '"&gt;HERE&lt;/a&gt; to login';
}

try {
    if (isset($_SESSION['access_token']) &amp;&amp; $client-&gt;getAccessToken()) {

        $messages = $service-&gt;users_messages-&gt;listUsersMessages('me',['maxResults'=&gt;2, 'labelids'=&gt; 'INBOX']);
        print_r($messages);
        exit();

    }
} catch (Google_Auth_Exception $e) {
    $loginUrl = $client-&gt;createAuthUrl();
    echo 'Error: ' . $e-&gt;getMessage;
    echo '&lt;br&gt;Click &lt;a href="' . $loginUrl . '"&gt;HERE&lt;/a&gt; to re-login';
}
</code></pre>