Google 드라이브의 튜토리얼을 따르면 인증/액세스 토큰을 유지하기 위해 매번 인증/승인을 요청할 필요가 없도록 새로 고침 토큰을 사용해야한다고합니다 우리는 API 호출을합니다.Google 드라이브 API 승인 문제
코드 :
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
$client = new Google_Client();
// Get your credentials from the console
$client->setClientId('client ID');
$client->setClientSecret('client secret');
$client->setRedirectUri('URL');
$client->setScopes(array('https://www.googleapis.com/auth/drive'));
$client->setAccessType('offline');
$service = new Google_DriveService($client);
$authUrl = $client->createAuthUrl();
// Exchange authorization code for access token
$accessToken = $client->authenticate();
$client->setAccessToken($accessToken);
$files = $service->files->listFiles();
echo "<pre>"; print_r($files);
이 나에게 파일 및 폴더의 목록을 제공하지만이 페이지를 새로 고침 할 때마다 그것이 구글의 인증 페이지로 날 다시 걸립니다. 액세스 토큰을 데이터베이스에 저장할 수 있지만이를 사용하고 사용자로부터 권한을 다시 요청하지 않고 API 호출을 수행하는 방법 ??
의견이 있으십니까 ??
감사합니다,
아니 켓
'Google_Auth_AssertionCredentials'에 문제가있어서 'Google_AssertionCredentials'에 파일 및 변경 기능이 있습니다. 하지만 지금 문제가 있습니다 :'PHP 치명적인 오류 : 75 행의 google_drive \ vendor \ google \ apiclient-services \ src \ Google \ Service \ Drive.php에서 생성자를 호출 할 수 없습니다. ' – Peter