我想將文件上傳到Google雲端硬盤但無法上傳。我有產品名稱:如demo_google_drive_app_v1,客戶端ID和客戶端密鑰,我使用下面的代碼,但我得到錯誤,我想我沒有得到適當的SDK上傳文件到谷歌驅動器我是新來的PHP和谷歌驅動器,並搜索了很多答案,但無法得到它。現在我收到以下錯誤消息, 如果有人幫我解決我的問題,我將非常感謝。無法使用php將文件上傳到Google雲端硬盤
Fatal error: Class 'Config' not found in C:\wamp\www\upload_drive\Google-Drive-PHP-API....\src\Google\Client.php on line 80
<?php
/*
* Simplified version of quickstart.php found on http://developers.google.com/drive/quickstart-php
*
*/
require_once 'google-api-php/src/Google/Client.php';
require_once 'google-api-php/src/Google/Service.php';
$client = new Google_Client();
$client = new Google_Client();
// Get your credentials from the console
$client->setClientId('XXXXXXXXXXXXXXX.apps.googleusercontent.com');
$client->setClientSecret('XXXXXXXXXXXXXXXXXXXX');
$client->setRedirectUri('');
$client->setScopes(array('https://www.googleapis.com/auth/drive.file'));
session_start();
if (isset($_GET['code']) || (isset($_SESSION['access_token']) && $_SESSION['access_token'])) {
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
} else
$client->setAccessToken($_SESSION['access_token']);
$service = new Google_Service_Drive($client);
//Insert a file
$file = new Google_Service_Drive_DriveFile();
$file->setTitle(uniqid().'.jpg');
$file->setDescription('A test document');
$file->setMimeType('image/jpeg');
$data = file_get_contents('a.jpg');
$createdFile = $service->files->insert($file, array(
'data' => $data,
'mimeType' => 'image/jpeg',
'uploadType' => 'multipart'
));
print_r($createdFile);
} else {
$authUrl = $client->createAuthUrl();
header('Location: ' . $authUrl);
exit();
}
我建議你從教程檢查代碼再次證明代碼是老https://developers.google.com/drive/web/quickstart/php – DaImTo