I'm trying to integrate Google Drive within our website. What we would like to do is to copy a file from Drive to our server, you know, kind of : Send to My Files. When i try to integrate i am facing the following error
My tried code:
require_once(ROOT . DS . 'vendor' . DS . 'google-api-php-client' . DS . 'vendor' . DS . 'autoload.php');
define('APPLICATION_NAME', 'Drive API PHP Quickstart');
define('CREDENTIALS_PATH', ROOT . DS . 'vendor' . DS. 'google-api-php-client' . DS .'vendor' . DS . 'drive-php-quickstart.json');
define('CLIENT_SECRET_PATH', ROOT . DS . 'vendor' . DS. 'google-api-php-client' . DS . 'vendor' . DS . 'client_secret.json');
define('SCOPES', implode(' ', array(\Google_Service_Drive::DRIVE_METADATA_READONLY)));
$client = new \Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(SCOPES);
$client->setAuthConfig(CLIENT_SECRET_PATH);
$client->setAccessType('offline');
// Load previously authorized credentials from a file.
$credentialsPath = $this->expandHomeDirectory(CREDENTIALS_PATH);
if (file_exists($credentialsPath)) {
$accessToken = json_decode(file_get_contents($credentialsPath), true);
} else {
// Request authorization from the user.
$authUrl = $client->createAuthUrl();
printf("Open the following link in your browser:\n%s\n", $authUrl);
print 'Enter verification code: ';
$authCode = trim(fgets(STDIN));
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
// Store the credentials to disk.
if (!file_exists(dirname($credentialsPath))) {
mkdir(dirname($credentialsPath), 0700, true);
}
file_put_contents($credentialsPath, json_encode($accessToken));
printf("Credentials saved to %s\n", $credentialsPath);
}
$client->setAccessToken($accessToken);
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
file_put_contents($credentialsPath, json_encode($client->getAccessToken()));
}