Я прочитал все сведения об этой ошибке, но все же я понятия не имею, что не так ... Итак, мне просто нужно получить список электронных писем пользователей.Недостаточно разрешения API Gmail
В API-консоли я создал проект и учетные данные. Кроме того, у меня есть ключ API ...
В Dashboard я включена Gmail API: http://joxi.ru/1A5bJvMhKo58Br
В моем приложении после принятия разрешения я получил эту ошибку:
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
Вот код войдите в систему:
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->setClientId($clientId);
$client->setClientSecret($clientSecret);
$client->setRedirectUri($redirectUri);
$client->setDeveloperKey('DEV KEY FROM API CONSOLE');
//$client->addScope('https://mail.google.com/');
//$client->setAuthConfig('client_secret.json');
$client->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->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($url, FILTER_VALIDATE_URL));
}
if (isset($_SESSION['access_token'])) {
$client->setAccessToken($_SESSION['access_token']);
$drive_service = new Google_Service_Drive($client);
$files_list = $drive_service->files->listFiles(array())->getItems();
echo json_encode($files_list);
} else {
$loginUrl = $client->createAuthUrl();
echo 'Click <a href="' . $loginUrl . '">HERE</a> to login';
}
try {
if (isset($_SESSION['access_token']) && $client->getAccessToken()) {
$messages = $service->users_messages->listUsersMessages('me',['maxResults'=>2, 'labelids'=> 'INBOX']);
print_r($messages);
exit();
}
} catch (Google_Auth_Exception $e) {
$loginUrl = $client->createAuthUrl();
echo 'Error: ' . $e->getMessage;
echo '<br>Click <a href="' . $loginUrl . '">HERE</a> to re-login';
}
hm ... эта опция уже включена в использовании учетной записи ... но по-прежнему такая же ошибка –
возможно Я должен включить некоторый другой API, чтобы он работал? –