2015-08-18 128 views
1

我想将文件上传到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(); 
} 
+0

我建议你从教程检查代码再次证明代码是老https://developers.google.com/drive/web/quickstart/php – DaImTo

回答

1

我想你应该有在顶部:

require_once 'google-api-php-client/src/Google/autoload.php'; 

或添加的config.php手动

require_once(path_to/Config.php) 

点击此处查看:https://github.com/google/google-api-php-client

简单的方法将包括autoload在顶部,因为它是在提示安装说明:

require_once 'google-api-php-client/src/Google/autoload.php'; 
+1

的自动加载行应该使这项工作。 – Rg14

+0

@ Rg14是的,如果它将包括,我会更新我的文章 –

相关问题